<!DOCTYPE html>
<html lang="en-US">
    <head>
        <title>Bit::Vector - metacpan.org</title>
        <link rel="preload" as="fetch" href="https://metacpan.org/account/login_status" crossorigin="anonymous" />
        <link href="https://metacpan.org/_assets/b8ccceeed47a0652049703d99326a9cea4933443.css" rel="stylesheet" type="text/css">
        <script src="https://metacpan.org/_assets/6bfedafe2d7caa915b7d84f61b45936818e3242e.js" type="text/javascript" defer></script>
        <link rel="alternate" type="application/rss+xml" title="Recent CPAN Uploads of Bit-Vector - MetaCPAN" href="https://metacpan.org/dist/Bit-Vector/releases.rss" />
        <link rel="canonical" href="./Bit::Vector.html" />
        <meta name="description" content="Efficient bit vector, set of integers and &quot;big int&quot; math library" />
        <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=5">
        <link rel="shortcut icon" href="https://metacpan.org/static/icons/favicon.ico">
        <link rel="apple-touch-icon" sizes="152x152" href="https://metacpan.org/static/icons/apple-touch-icon.png">
        <link rel="search" href="https://metacpan.org/static/opensearch.xml" type="application/opensearchdescription+xml" title="MetaCPAN">
        <script>
          (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
          (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
          m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
          })(window,document,'script','//www.google-analytics.com/analytics.js','ga');

          (function(skey, ga_id){
            ga('create', ga_id, {
              siteSpeedSampleRate : 100,
              storage             : 'none',
              clientId            : localStorage.getItem(skey)
            });
            ga(function(tracker) {
              localStorage.setItem(skey, tracker.get('clientId'));
            });
            ga('send', 'pageview');
          })('ga:clientId', 'UA-27829474-1');
        </script>
<meta name="twitter:card"        content="summary" />
<meta name="twitter:url"         content="https://metacpan.org/pod/Bit::Vector" />
<meta name="twitter:title"       content="Bit::Vector" />
<meta name="twitter:description" content="" />
<meta name="twitter:site"        content="metacpan" />
    </head>
    <body>
        <nav class="navbar navbar-default" role="navigation">
            <div class="header-logo-large hidden-xs">
              <a href="https://metacpan.org/" tabindex="0">
                <svg class="logo" aria-label="MetaCPAN">
                  <use class="logo" href="/static/images/metacpan-logo.svg#logo" />
                </svg>
              </a>
            </div>
            <div class="header-logo-icon visible-xs">
              <a href="https://metacpan.org/">
                <svg class="logo" aria-label="MetaCPAN">
                  <use class="logo" href="/static/images/metacpan-logo.svg#dots" />
                </svg>
              </a>
            </div>
            <ul class="nav navbar-nav menu-items hidden-xs hidden-sm">
              <li><a href="https://metacpan.org/about">About</a></li>
              <li><a href="https://metacpan.org/about/sponsors">Sponsor</a></li>
              <li><a href="https://grep.metacpan.org/">grep::cpan</a></li>
              <li><a href="https://metacpan.org/recent">Recent</a></li>
              <li><a href="https://metacpan.org/about/faq">FAQ</a></li>
              <li><a href="https://metacpan.org/tools">Tools</a></li>
              <li><a href="https://fastapi.metacpan.org/">API</a></li>
            </ul>
            <ul class="nav navbar-nav navbar-right">
                <button type="button" class="searchbar-btn visible-xs visible-sm">
                    <i class="fa fa-search button-fa-icon"></i>
                </button>
                <form action="https://metacpan.org/search" class="searchbar-form visible-md visible-lg search-form form-horizontal">
                   <input type="hidden" name="size" id="metacpan_search-size" value="20">
                  <div class="form-group">
                      <div class="search-group">
                        <i class="fa fa-search"></i>
                        <input type="text" name="q" placeholder="Search the CPAN" size="41" autocorrect="off" autocapitalize="off" spellcheck="false" id="metacpan_search-input" class="form-control" value="">
                      </div>
                  </div>
                </form>
                    <li class="icon-slidepanel visible-xs visible-sm">
                      <button data-toggle="slidepanel" data-target=".slidepanel">
                        <span class="button-fa-icon">
                          <i class="fa fa-bars slidepanel-open"></i>
                          <i class="fa fa-times slidepanel-close"></i>
                        </span>
                      </button>
                    </li>
                <form action="https://metacpan.org/account/logout" method="POST" id="metacpan-logout"></form>
                <li class="dropdown logged_in" style="display: none;">
                    <button type="button" class="dropdown-toggle" data-toggle="dropdown">
                      <i class="fa fa-user button-fa-icon logged-in-icon" aria-hidden="true"></i>
                      <i class="fas fa-chevron-down"></i>
                    </button>
                    <ul class="dropdown-menu">
                        <li><a href="https://metacpan.org/account/identities">Identities</a></li>
                        <li><a href="https://metacpan.org/account/profile">Profile</a></li>
                        <li><a href="https://metacpan.org/account/favorite/list">Favorites</a></li>
                        <li>
                            <a href="./Bit::Vector.html#" type="button" onclick="$('#metacpan-logout').submit(); return false">
                              Logout
                            </a>
                        </li>
                    </ul>
                </li>
                <li class="dropdown logged_out" style="display: none;">
                    <button type="button" class="dropdown-toggle" data-toggle="dropdown">
                      <i class="fa fa-user button-fa-icon" aria-hidden="true"></i>
                      <i class="fas fa-chevron-down"></i>
                    </button>
                    <ul class="dropdown-menu">
                        <li>
                            <a href="https://metacpan.org/login/github">
                                <i class="fab fa-github fa-fw"></i>
                                GitHub
                            </a>
                        </li>
                        <li>
                            <a href="https://metacpan.org/login/twitter">
                                <i class="fab fa-twitter fa-fw"></i>
                                Twitter
                            </a>
                        </li>
                        <li>
                            <a href="https://metacpan.org/login/google">
                                <i class="fab fa-google fa-fw"></i>
                                Google
                            </a>
                        </li>
                    </ul>
                </li>
                <li class="dropdown logged_placeholder">
                    <button>
                      <i class="fa fa-user button-fa-icon" aria-hidden="true"></i>
                    </button>
                </li>
            </ul>
        </nav>
        <div class="page-content ">
          <!--
          <div class="top-notify-banner">
            <i class="fas fa-info-circle"></i>
          </div>
          -->
          <nav class="sidebar">
            <div class="slidepanel">
              <ul class="nav-list ">
    <li class="nav-header no-margin-top">
      <div class="ttip" data-toggle="tooltip" data-placement="bottom" title="The date that this version of Bit-Vector was released.">
      <span class="relatize">20 Nov 2014 09:49:01 UTC</span>
    </li>
  <li>
    Distribution: <a href="https://metacpan.org/dist/Bit-Vector">Bit-Vector</a>
  </li>
  <li>
    <a data-keyboard-shortcut="g s" href="https://metacpan.org/dist/Bit-Vector/source/lib/Bit/Vector/String.pm">Source</a>
    (<a href="https://metacpan.org/dist/Bit-Vector/source/lib/Bit/Vector/String.pm?raw=1">raw</a>)
  </li>
  <li>
    <a data-keyboard-shortcut="g p" href="https://metacpan.org/dist/Bit-Vector/source/Vector.pod">Pod Source</a>
    (<a href="https://metacpan.org/dist/Bit-Vector/source/Vector.pod?raw=1">raw</a>)
  </li>
  <li>
    <a data-keyboard-shortcut="g b" href="https://metacpan.org/dist/Bit-Vector/source/lib/Bit/Vector">Browse</a>
    (<a href="https://metacpan.org/dist/Bit-Vector/source/lib/Bit/Vector?raw=1">raw</a>)
  </li>
    <li>
      <a data-keyboard-shortcut="g c" href="https://metacpan.org/dist/Bit-Vector/changes">Changes</a>
    </li>
    <li>
      <a class="nopopup" href="https://metacpan.org/dist/Bit-Vector/contribute">How to Contribute</a>
    </li>
    <li>
      <a rel="noopener nofollow" data-keyboard-shortcut="g i" href="https://rt.cpan.org/Public/Dist/Display.html?Name=Bit-Vector">Issues</a>
      (16)
    </li>
    <li>
      <a rel="noopener nofollow" href="http://matrix.cpantesters.org/?dist=Bit-Vector+7.4" title="Matrix">Testers</a>
        <span title="(pass / fail / na)">(<a rel="noopener nofollow" href="https://www.cpantesters.org/distro/B/Bit-Vector.html?oncpan=1&amp;distmat=1&amp;version=7.4&amp;grade=2" style="color: #090">15695</a> / <a rel="noopener nofollow" href="https://www.cpantesters.org/distro/B/Bit-Vector.html?oncpan=1&amp;distmat=1&amp;version=7.4&amp;grade=3" style="color: #900">32</a> / <a rel="noopener nofollow" href="https://www.cpantesters.org/distro/B/Bit-Vector.html?oncpan=1&amp;distmat=1&amp;version=7.4&amp;grade=4">0</a>)</span>
    </li>
    <li>
      <a rel="noopener nofollow" href="http://cpants.cpanauthors.org/release/STBEY/Bit-Vector-7.4">Kwalitee</a>
    </li>
    <li>
      <div class="ttip" data-toggle="tooltip" data-placement="bottom" title="The # people with an indexing permission on Bit-Vector who have released something to CPAN in the last 2 years (i.e. the # people likely able to release critical fixes in a timely manner)">
      Bus factor: 1
      </div>
    </li>
    <li>
      <a rel="noopener nofollow" href="http://cpancover.com/latest/Bit-Vector-7.4/index.html">49.69% Coverage </a>
    </li>
    <li>
      License: unknown
    </li>
    <li class="nav-header">Activity</li>
    <li>
<div class="activity-graph">
    <img src="https://metacpan.org/dist/Bit-Vector/activity.svg?res=month" />
    <div class="comment">24 month</div>
</div>
    </li>
    <li class="nav-header">Tools</li>
    <li>
      <a itemprop="downloadUrl" href="https://cpan.metacpan.org/authors/id/S/ST/STBEY/Bit-Vector-7.4.tar.gz">
      Download (<span itemprop="fileSize">132.78KB</span>)</a>
    </li>
    <li>
      <a href="https://explorer.metacpan.org/?url=%2Fmodule%2FSTBEY%2FBit-Vector-7.4%2Flib%2FBit%2FVector%2FString.pm">
        MetaCPAN Explorer
      </a>
    </li>
    <li>
      <a href="https://metacpan.org/dist/Bit-Vector/permissions">
        Permissions
      </a>
    </li>
    <li>
      <a href="https://metacpan.org/dist/Bit-Vector/releases.rss">
        Subscribe to distribution
      </a>
    </li>
    <li>
      <button class="btn btn-link" data-toggle="modal" data-target="#metacpan_install-instructions-dialog">
        Install Instructions
      </button>
    </li>
    <li>
      <form action="https://metacpan.org/search">
        <input type="hidden" name="q" value="dist:Bit-Vector">
        <input type="search" name="q" placeholder="Search distribution" class="form-control tool-bar-form">
        <input type="submit" style="display: none">
      </form>
    </li>
    <li>
      <form action="https://grep.metacpan.org/search">
        <input type="hidden" name="qd" value="Bit-Vector">
        <input type="hidden" name="source" value="metacpan">
        <input type="search" name="q" placeholder="grep distribution" class="form-control tool-bar-form">
        <input type="submit" style="display: none">
     </form>
    </li>
    <li class="version-jump">
<select onchange="document.location.href=&#39;/release/&#39;+this.value+&#39;/view/lib/Bit/Vector/String.pm&#39;" class="form-control tool-bar-form">
  <option disabled selected>Jump to version</option>
<option
  disabled
  value="STBEY/Bit-Vector-7.4"
>7.4
  (STBEY on 2014-11-20)</option>
<option
  
  value="STBEY/Bit-Vector-7.3"
>7.3
  (STBEY on 2013-06-01)</option>
<option
  
  value="TWEGNER/Bit-Vector-6.3-bin56Mac"
>6.3-bin56Mac
  (TWEGNER on 2002-12-20)</option>
<option
  
  value="TWEGNER/Bit-Vector-6.0-bin-MacOS"
>6.0-bin-MacOS
  (TWEGNER on 2001-02-14)</option>
<option
  
  value="ASANDSTRM/Bit-Vector-5.6-bin-2-MacOS"
>5.6-bin-2-MacOS
  (ASANDSTRM on 1999-03-09)</option>
<optgroup label="BackPAN">'
<option
  
  value="STBEY/Bit-Vector-7.2"
>7.2
  (STBEY on 2012-05-17)</option>
<option
  
  value="ANDK/Bit-Vector-7.2"
>7.2
  (ANDK on 2012-03-09)</option>
<option
  
  value="ANDK/Bit-Vector-7.2-TRIAL"
>7.2-TRIAL DEV
  (ANDK on 2012-03-03)</option>
<option
  
  value="STBEY/Bit-Vector-7.1"
>7.1
  (STBEY on 2009-09-30)</option>
<option
  
  value="STBEY/Bit-Vector-7.0"
>7.0
  (STBEY on 2009-08-24)</option>
<option
  
  value="STBEY/Bit-Vector-6.9"
>6.9
  (STBEY on 2009-08-12)</option>
<option
  
  value="STBEY/Bit-Vector-6.8"
>6.8
  (STBEY on 2009-08-10)</option>
<option
  
  value="STBEY/Bit-Vector-6.7"
>6.7
  (STBEY on 2009-08-08)</option>
<option
  
  value="STBEY/Bit-Vector-6.6"
>6.6
  (STBEY on 2009-07-27)</option>
<option
  
  value="STBEY/Bit-Vector-6.5"
>6.5
  (STBEY on 2009-07-26)</option>
<option
  
  value="STBEY/Bit-Vector-6.4"
>6.4
  (STBEY on 2004-10-03)</option>
<option
  
  value="STBEY/Bit-Vector-6.3"
>6.3
  (STBEY on 2002-09-28)</option>
<option
  
  value="STBEY/Bit-Vector-6.2"
>6.2
  (STBEY on 2002-09-16)</option>
<option
  
  value="TWEGNER/Bit-Vector-6.1-bin56Mac"
>6.1-bin56Mac
  (TWEGNER on 2001-12-13)</option>
<option
  
  value="STBEY/Bit-Vector-6.1"
>6.1
  (STBEY on 2001-10-09)</option>
<option
  
  value="STBEY/Bit-Vector-6.0"
>6.0
  (STBEY on 2000-10-08)</option>
<option
  
  value="STBEY/Bit-Vector-5.8"
>5.8
  (STBEY on 2000-07-24)</option>
<option
  
  value="STBEY/Bit-Vector-5.7"
>5.7
  (STBEY on 1999-05-26)</option>
<option
  
  value="ASANDSTRM/Bit-Vector-5.6-bin-1-MacOS"
>5.6-bin-1-MacOS
  (ASANDSTRM on 1999-03-08)</option>
<option
  
  value="STBEY/Bit-Vector-5.6"
>5.6
  (STBEY on 1998-11-02)</option>
<option
  
  value="STBEY/Bit-Vector-5.5"
>5.5
  (STBEY on 1998-09-21)</option>
<option
  
  value="STBEY/Bit-Vector-5.4"
>5.4
  (STBEY on 1998-09-15)</option>
<option
  
  value="STBEY/Bit-Vector-5.3"
>5.3
  (STBEY on 1998-05-12)</option>
<option
  
  value="STBEY/Bit-Vector-5.2"
>5.2
  (STBEY on 1998-03-31)</option>
<option
  
  value="STBEY/Bit-Vector-5.1"
>5.1
  (STBEY on 1998-03-09)</option>
<option
  
  value="STBEY/Bit-Vector-5.0"
>5.0
  (STBEY on 1998-03-02)</option>
<option
  
  value="STBEY/Bit-Vector-5.0b8"
>5.0b8
  (STBEY on 1998-02-27)</option>
<option
  
  value="STBEY/Bit-Vector-5.0b7"
>5.0b7
  (STBEY on 1998-02-25)</option>
<option
  
  value="STBEY/Bit-Vector-5.0b6"
>5.0b6
  (STBEY on 1998-02-24)</option>
<option
  
  value="STBEY/Bit-Vector-5.0b4"
>5.0b4
  (STBEY on 1998-02-18)</option>
<option
  
  value="STBEY/Bit-Vector-5.0b2"
>5.0b2
  (STBEY on 1997-12-29)</option>
<option
  
  value="STBEY/Bit-Vector-5.0b1"
>5.0b1
  (STBEY on 1997-10-13)</option>
<option
  
  value="STBEY/Bit-Vector-4.2"
>4.2
  (STBEY on 1997-07-16)</option>
<option
  
  value="STBEY/Bit-Vector-4.1"
>4.1
  (STBEY on 1997-06-30)</option>
<option
  
  value="STBEY/Bit-Vector-4.0"
>4.0
  (STBEY on 1997-04-23)</option>
</optgroup>
</select>
    </li>
    <li class="version-diff">
<select onchange="document.location.href='/release/STBEY/Bit-Vector-7.4/diff/' + encodeURIComponent(this.value) + '/lib/Bit/Vector/String.pm'
" class="form-control tool-bar-form">
  <option disabled selected>Diff with version</option>
<option
  disabled
  value="STBEY/Bit-Vector-7.4"
>7.4
  (STBEY on 2014-11-20)</option>
<option
  
  value="STBEY/Bit-Vector-7.3"
>7.3
  (STBEY on 2013-06-01)</option>
<option
  
  value="TWEGNER/Bit-Vector-6.3-bin56Mac"
>6.3-bin56Mac
  (TWEGNER on 2002-12-20)</option>
<option
  
  value="TWEGNER/Bit-Vector-6.0-bin-MacOS"
>6.0-bin-MacOS
  (TWEGNER on 2001-02-14)</option>
<option
  
  value="ASANDSTRM/Bit-Vector-5.6-bin-2-MacOS"
>5.6-bin-2-MacOS
  (ASANDSTRM on 1999-03-09)</option>
<optgroup label="BackPAN">'
<option
  
  value="STBEY/Bit-Vector-7.2"
>7.2
  (STBEY on 2012-05-17)</option>
<option
  
  value="ANDK/Bit-Vector-7.2"
>7.2
  (ANDK on 2012-03-09)</option>
<option
  
  value="ANDK/Bit-Vector-7.2-TRIAL"
>7.2-TRIAL DEV
  (ANDK on 2012-03-03)</option>
<option
  
  value="STBEY/Bit-Vector-7.1"
>7.1
  (STBEY on 2009-09-30)</option>
<option
  
  value="STBEY/Bit-Vector-7.0"
>7.0
  (STBEY on 2009-08-24)</option>
<option
  
  value="STBEY/Bit-Vector-6.9"
>6.9
  (STBEY on 2009-08-12)</option>
<option
  
  value="STBEY/Bit-Vector-6.8"
>6.8
  (STBEY on 2009-08-10)</option>
<option
  
  value="STBEY/Bit-Vector-6.7"
>6.7
  (STBEY on 2009-08-08)</option>
<option
  
  value="STBEY/Bit-Vector-6.6"
>6.6
  (STBEY on 2009-07-27)</option>
<option
  
  value="STBEY/Bit-Vector-6.5"
>6.5
  (STBEY on 2009-07-26)</option>
<option
  
  value="STBEY/Bit-Vector-6.4"
>6.4
  (STBEY on 2004-10-03)</option>
<option
  
  value="STBEY/Bit-Vector-6.3"
>6.3
  (STBEY on 2002-09-28)</option>
<option
  
  value="STBEY/Bit-Vector-6.2"
>6.2
  (STBEY on 2002-09-16)</option>
<option
  
  value="TWEGNER/Bit-Vector-6.1-bin56Mac"
>6.1-bin56Mac
  (TWEGNER on 2001-12-13)</option>
<option
  
  value="STBEY/Bit-Vector-6.1"
>6.1
  (STBEY on 2001-10-09)</option>
<option
  
  value="STBEY/Bit-Vector-6.0"
>6.0
  (STBEY on 2000-10-08)</option>
<option
  
  value="STBEY/Bit-Vector-5.8"
>5.8
  (STBEY on 2000-07-24)</option>
<option
  
  value="STBEY/Bit-Vector-5.7"
>5.7
  (STBEY on 1999-05-26)</option>
<option
  
  value="ASANDSTRM/Bit-Vector-5.6-bin-1-MacOS"
>5.6-bin-1-MacOS
  (ASANDSTRM on 1999-03-08)</option>
<option
  
  value="STBEY/Bit-Vector-5.6"
>5.6
  (STBEY on 1998-11-02)</option>
<option
  
  value="STBEY/Bit-Vector-5.5"
>5.5
  (STBEY on 1998-09-21)</option>
<option
  
  value="STBEY/Bit-Vector-5.4"
>5.4
  (STBEY on 1998-09-15)</option>
<option
  
  value="STBEY/Bit-Vector-5.3"
>5.3
  (STBEY on 1998-05-12)</option>
<option
  
  value="STBEY/Bit-Vector-5.2"
>5.2
  (STBEY on 1998-03-31)</option>
<option
  
  value="STBEY/Bit-Vector-5.1"
>5.1
  (STBEY on 1998-03-09)</option>
<option
  
  value="STBEY/Bit-Vector-5.0"
>5.0
  (STBEY on 1998-03-02)</option>
<option
  
  value="STBEY/Bit-Vector-5.0b8"
>5.0b8
  (STBEY on 1998-02-27)</option>
<option
  
  value="STBEY/Bit-Vector-5.0b7"
>5.0b7
  (STBEY on 1998-02-25)</option>
<option
  
  value="STBEY/Bit-Vector-5.0b6"
>5.0b6
  (STBEY on 1998-02-24)</option>
<option
  
  value="STBEY/Bit-Vector-5.0b4"
>5.0b4
  (STBEY on 1998-02-18)</option>
<option
  
  value="STBEY/Bit-Vector-5.0b2"
>5.0b2
  (STBEY on 1997-12-29)</option>
<option
  
  value="STBEY/Bit-Vector-5.0b1"
>5.0b1
  (STBEY on 1997-10-13)</option>
<option
  
  value="STBEY/Bit-Vector-4.2"
>4.2
  (STBEY on 1997-07-16)</option>
<option
  
  value="STBEY/Bit-Vector-4.1"
>4.1
  (STBEY on 1997-06-30)</option>
<option
  
  value="STBEY/Bit-Vector-4.0"
>4.0
  (STBEY on 1997-04-23)</option>
</optgroup>
</select>
    </li>

    <li>
<ul class="dependencies">
  <li class="nav-header">Dependencies</li>
  <li><a href="./Carp::Clan.html" title="Carp::Clan" class="ellipsis">Carp::Clan</a></li>
  <li><a href="https://metacpan.org/pod/Storable" title="Storable" class="ellipsis">Storable</a></li>
  <li><i class="ttip" title="dynamic_config enabled">and possibly others</i></li>
  <li>
    <hr>
  </li>
  <li>
    <a href="https://metacpan.org/module/Bit::Vector/requires">Reverse dependencies</a>
  </li>
  <li>
    <a href="http://deps.cpantesters.org/?module=Bit%3A%3AVector">CPAN Testers List</a>
  </li>
  <li>
    <a href="https://cpandeps.grinnz.com/?dist=Bit-Vector">Dependency graph</a>
  </li>
</ul>
    </li>
    <li class="nav-header">Permalinks</li>
    <li>
      <a href="https://metacpan.org/release/STBEY/Bit-Vector-7.4/view/lib/Bit/Vector/String.pm">This version</a>
    </li>
    <li>
      <a href="./Bit::Vector.html">Latest version</a>
    </li>
    <li>
<div class="plussers">
<div class="nav-header">++ed by:</div>
<div>
<a class="display-all" href="https://metacpan.org/author/AYOUNG"><img src="https://www.gravatar.com/avatar/8d1e4946c288fbe87d1e0394f3e41b24?d=identicon&amp;s=20" title="AYOUNG" alt="AYOUNG"></a>
<a class="display-all" href="https://metacpan.org/author/EGOR"><img src="https://www.gravatar.com/avatar/d1b2873e176897abb1f26be3a92e771d?d=identicon&amp;s=20" title="EGOR" alt="EGOR"></a>
<a class="display-all" href="https://metacpan.org/author/ZMUGHAL"><img src="https://www.gravatar.com/avatar/82e7c54d334bfdfd32594d34583d32bc?d=identicon&amp;s=20" title="ZMUGHAL" alt="ZMUGHAL"></a>
<a class="display-all" href="https://metacpan.org/author/XAV"><img src="https://www.gravatar.com/avatar/37f9cbd6749507cadc1df1efeec95771?d=identicon&amp;s=20" title="XAV" alt="XAV"></a>
<a class="display-all" href="https://metacpan.org/author/KEEDI"><img src="https://www.gravatar.com/avatar/95f905a7a4ccc573c711e9d264c0fde8?d=identicon&amp;s=20" title="KEEDI" alt="KEEDI"></a>
</div>
<!-- Display counts of plussers-->
<div>
    <a href="https://metacpan.org/dist/Bit-Vector/plussers">5 PAUSE users</a>
</div>
<div>
    2 non-PAUSE users
</div>
</div>
    </li>
    <li>
    </li>
              </ul>
            </div>
          </nav>
          <div class="content-navigation">
<div class="breadcrumbs">
  <span>
    <a data-keyboard-shortcut="g a" rel="author" href="https://metacpan.org/author/STBEY" class="author-name">Steffen Beyer</a>
  </span>
  <span>&nbsp;/&nbsp;</span>
  <div class="release dist-release status-latest maturity-released">
    <span class="dropdown"><b class="caret"></b></span>
<select onchange="document.location.href=&#39;/release/&#39;+this.value+&#39;/view/lib/Bit/Vector/String.pm&#39;" class="">
<option
  selected
  value="STBEY/Bit-Vector-7.4"
>7.4
  (STBEY on 2014-11-20)</option>
<option
  
  value="STBEY/Bit-Vector-7.3"
>7.3
  (STBEY on 2013-06-01)</option>
<option
  
  value="TWEGNER/Bit-Vector-6.3-bin56Mac"
>6.3-bin56Mac
  (TWEGNER on 2002-12-20)</option>
<option
  
  value="TWEGNER/Bit-Vector-6.0-bin-MacOS"
>6.0-bin-MacOS
  (TWEGNER on 2001-02-14)</option>
<option
  
  value="ASANDSTRM/Bit-Vector-5.6-bin-2-MacOS"
>5.6-bin-2-MacOS
  (ASANDSTRM on 1999-03-09)</option>
<optgroup label="BackPAN">'
<option
  
  value="STBEY/Bit-Vector-7.2"
>7.2
  (STBEY on 2012-05-17)</option>
<option
  
  value="ANDK/Bit-Vector-7.2"
>7.2
  (ANDK on 2012-03-09)</option>
<option
  
  value="ANDK/Bit-Vector-7.2-TRIAL"
>7.2-TRIAL DEV
  (ANDK on 2012-03-03)</option>
<option
  
  value="STBEY/Bit-Vector-7.1"
>7.1
  (STBEY on 2009-09-30)</option>
<option
  
  value="STBEY/Bit-Vector-7.0"
>7.0
  (STBEY on 2009-08-24)</option>
<option
  
  value="STBEY/Bit-Vector-6.9"
>6.9
  (STBEY on 2009-08-12)</option>
<option
  
  value="STBEY/Bit-Vector-6.8"
>6.8
  (STBEY on 2009-08-10)</option>
<option
  
  value="STBEY/Bit-Vector-6.7"
>6.7
  (STBEY on 2009-08-08)</option>
<option
  
  value="STBEY/Bit-Vector-6.6"
>6.6
  (STBEY on 2009-07-27)</option>
<option
  
  value="STBEY/Bit-Vector-6.5"
>6.5
  (STBEY on 2009-07-26)</option>
<option
  
  value="STBEY/Bit-Vector-6.4"
>6.4
  (STBEY on 2004-10-03)</option>
<option
  
  value="STBEY/Bit-Vector-6.3"
>6.3
  (STBEY on 2002-09-28)</option>
<option
  
  value="STBEY/Bit-Vector-6.2"
>6.2
  (STBEY on 2002-09-16)</option>
<option
  
  value="TWEGNER/Bit-Vector-6.1-bin56Mac"
>6.1-bin56Mac
  (TWEGNER on 2001-12-13)</option>
<option
  
  value="STBEY/Bit-Vector-6.1"
>6.1
  (STBEY on 2001-10-09)</option>
<option
  
  value="STBEY/Bit-Vector-6.0"
>6.0
  (STBEY on 2000-10-08)</option>
<option
  
  value="STBEY/Bit-Vector-5.8"
>5.8
  (STBEY on 2000-07-24)</option>
<option
  
  value="STBEY/Bit-Vector-5.7"
>5.7
  (STBEY on 1999-05-26)</option>
<option
  
  value="ASANDSTRM/Bit-Vector-5.6-bin-1-MacOS"
>5.6-bin-1-MacOS
  (ASANDSTRM on 1999-03-08)</option>
<option
  
  value="STBEY/Bit-Vector-5.6"
>5.6
  (STBEY on 1998-11-02)</option>
<option
  
  value="STBEY/Bit-Vector-5.5"
>5.5
  (STBEY on 1998-09-21)</option>
<option
  
  value="STBEY/Bit-Vector-5.4"
>5.4
  (STBEY on 1998-09-15)</option>
<option
  
  value="STBEY/Bit-Vector-5.3"
>5.3
  (STBEY on 1998-05-12)</option>
<option
  
  value="STBEY/Bit-Vector-5.2"
>5.2
  (STBEY on 1998-03-31)</option>
<option
  
  value="STBEY/Bit-Vector-5.1"
>5.1
  (STBEY on 1998-03-09)</option>
<option
  
  value="STBEY/Bit-Vector-5.0"
>5.0
  (STBEY on 1998-03-02)</option>
<option
  
  value="STBEY/Bit-Vector-5.0b8"
>5.0b8
  (STBEY on 1998-02-27)</option>
<option
  
  value="STBEY/Bit-Vector-5.0b7"
>5.0b7
  (STBEY on 1998-02-25)</option>
<option
  
  value="STBEY/Bit-Vector-5.0b6"
>5.0b6
  (STBEY on 1998-02-24)</option>
<option
  
  value="STBEY/Bit-Vector-5.0b4"
>5.0b4
  (STBEY on 1998-02-18)</option>
<option
  
  value="STBEY/Bit-Vector-5.0b2"
>5.0b2
  (STBEY on 1997-12-29)</option>
<option
  
  value="STBEY/Bit-Vector-5.0b1"
>5.0b1
  (STBEY on 1997-10-13)</option>
<option
  
  value="STBEY/Bit-Vector-4.2"
>4.2
  (STBEY on 1997-07-16)</option>
<option
  
  value="STBEY/Bit-Vector-4.1"
>4.1
  (STBEY on 1997-06-30)</option>
<option
  
  value="STBEY/Bit-Vector-4.0"
>4.0
  (STBEY on 1997-04-23)</option>
</optgroup>
</select>
    <a data-keyboard-shortcut="g d" class="release-name" href="https://metacpan.org/dist/Bit-Vector">Bit-Vector-7.4</a>
  </div>
<span class="river-gauge-gauge">
  <svg width="24px"
       height="15px"
       version="1.1"
       xmlns="http://www.w3.org/2000/svg"
       xmlns:xlink="http://www.w3.org/1999/xlink">

    <g>
      <title>        River stage three &#10;
          • 32 direct dependents &#10;          • 384 total dependents
      </title>

      <rect x="0"  y="0" width="4" height="15" fill="#7ea3f2" />
      <rect x="5"  y="0" width="4" height="15" fill="#7ea3f2" />
      <rect x="10"  y="0" width="4" height="15" fill="#7ea3f2" />
      <rect x="15"  y="0" width="4" height="15" fill="#e4e2e2" />
      <rect x="20"  y="0" width="4" height="15" fill="#e4e2e2" />
    </g>
  </svg>

</span>
<div id="Bit-Vector-fav" class="logged_in">
<form action="https://metacpan.org/account/favorite/add" style="display: inline" onsubmit="return favDistribution(this)">
    <input type="hidden" name="remove" value="0">
    <input type="hidden" name="release" value="Bit-Vector-7.4">
    <input type="hidden" name="author" value="STBEY">
    <input type="hidden" name="distribution" value="Bit-Vector">
    <button type="submit" class="favorite highlight"><span>7</span> ++</button>
</form>
</div>
<div class="logged_out">
<a href="./Bit::Vector.html" onclick="alert('Please sign in to add favorites'); return false" class="favorite highlight">
<span>7</span> ++</a>
</div>
   / <span>Bit::Vector</span>
</div>
          </div>
          <main class="content">


<nav class="toc">
  <div class="toc-header"><strong>Contents</strong></div>
<ul>
  <li><a href="./Bit::Vector.html#NAME">NAME</a></li>
  <li><a href="./Bit::Vector.html#SYNOPSIS">SYNOPSIS</a>
    <ul>
      <li><a href="./Bit::Vector.html#OVERLOADED-OPERATORS">OVERLOADED OPERATORS</a></li>
      <li><a href="./Bit::Vector.html#MORE-STRING-IMPORT/EXPORT">MORE STRING IMPORT/EXPORT</a></li>
      <li><a href="./Bit::Vector.html#CLASS-METHODS">CLASS METHODS</a></li>
      <li><a href="./Bit::Vector.html#OBJECT-METHODS">OBJECT METHODS</a></li>
    </ul>
  </li>
  <li><a href="./Bit::Vector.html#IMPORTANT-NOTES">IMPORTANT NOTES</a></li>
  <li><a href="./Bit::Vector.html#DESCRIPTION">DESCRIPTION</a>
    <ul>
      <li><a href="./Bit::Vector.html#OVERLOADED-OPERATORS1">OVERLOADED OPERATORS</a></li>
      <li><a href="./Bit::Vector.html#MORE-STRING-IMPORT/EXPORT1">MORE STRING IMPORT/EXPORT</a></li>
      <li><a href="./Bit::Vector.html#CLASS-METHODS1">CLASS METHODS</a></li>
      <li><a href="./Bit::Vector.html#OBJECT-METHODS1">OBJECT METHODS</a></li>
    </ul>
  </li>
  <li><a href="./Bit::Vector.html#SEE-ALSO">SEE ALSO</a></li>
  <li><a href="./Bit::Vector.html#VERSION">VERSION</a></li>
  <li><a href="./Bit::Vector.html#AUTHOR">AUTHOR</a></li>
  <li><a href="./Bit::Vector.html#COPYRIGHT">COPYRIGHT</a></li>
  <li><a href="./Bit::Vector.html#LICENSE">LICENSE</a></li>
  <li><a href="./Bit::Vector.html#DISCLAIMER">DISCLAIMER</a></li>
</ul></nav>
<div class="pod anchors">
<h1 id="NAME">NAME</h1>

<p>Bit::Vector - Efficient bit vector, set of integers and &quot;big int&quot; math library</p>

<h1 id="SYNOPSIS">SYNOPSIS</h1>

<h2 id="OVERLOADED-OPERATORS"><a id="OVERLOADED"></a>OVERLOADED OPERATORS</h2>

<p>See <a href="http://man.he.net/man3/Bit::Vector::Overload">Bit::Vector::Overload(3)</a>.</p>

<h2 id="MORE-STRING-IMPORT/EXPORT"><a id="MORE"></a><a id="MORE-STRING-IMPORT-EXPORT"></a>MORE STRING IMPORT/EXPORT</h2>

<p>See <a href="http://man.he.net/man3/Bit::Vector::String">Bit::Vector::String(3)</a>.</p>

<h2 id="CLASS-METHODS"><a id="CLASS"></a>CLASS METHODS</h2>

<pre><code>  Version
      $version = Bit::Vector-&gt;Version();

  Word_Bits
      $bits = Bit::Vector-&gt;Word_Bits();  #  bits in a machine word

  Long_Bits
      $bits = Bit::Vector-&gt;Long_Bits();  #  bits in an unsigned long

  new
      $vector = Bit::Vector-&gt;new($bits);  #  bit vector constructor

      @veclist = Bit::Vector-&gt;new($bits,$count);

  new_Hex
      $vector = Bit::Vector-&gt;new_Hex($bits,$string);

  new_Bin
      $vector = Bit::Vector-&gt;new_Bin($bits,$string);

  new_Dec
      $vector = Bit::Vector-&gt;new_Dec($bits,$string);

  new_Enum
      $vector = Bit::Vector-&gt;new_Enum($bits,$string);

  Concat_List
      $vector = Bit::Vector-&gt;Concat_List(@vectors);</code></pre>

<h2 id="OBJECT-METHODS"><a id="OBJECT"></a>OBJECT METHODS</h2>

<pre><code>  new
      $vec2 = $vec1-&gt;new($bits);  #  alternative call of constructor

      @veclist = $vec-&gt;new($bits,$count);

  Shadow
      $vec2 = $vec1-&gt;Shadow();  #  new vector, same size but empty

  Clone
      $vec2 = $vec1-&gt;Clone();  #  new vector, exact duplicate

  Concat
      $vector = $vec1-&gt;Concat($vec2);

  Concat_List
      $vector = $vec1-&gt;Concat_List($vec2,$vec3,...);

  Size
      $bits = $vector-&gt;Size();

  Resize
      $vector-&gt;Resize($bits);
      $vector-&gt;Resize($vector-&gt;Size()+5);
      $vector-&gt;Resize($vector-&gt;Size()-5);

  Copy
      $vec2-&gt;Copy($vec1);

  Empty
      $vector-&gt;Empty();

  Fill
      $vector-&gt;Fill();

  Flip
      $vector-&gt;Flip();

  Primes
      $vector-&gt;Primes();  #  Sieve of Erathostenes

  Reverse
      $vec2-&gt;Reverse($vec1);

  Interval_Empty
      $vector-&gt;Interval_Empty($min,$max);

  Interval_Fill
      $vector-&gt;Interval_Fill($min,$max);

  Interval_Flip
      $vector-&gt;Interval_Flip($min,$max);

  Interval_Reverse
      $vector-&gt;Interval_Reverse($min,$max);

  Interval_Scan_inc
      if (($min,$max) = $vector-&gt;Interval_Scan_inc($start))

  Interval_Scan_dec
      if (($min,$max) = $vector-&gt;Interval_Scan_dec($start))

  Interval_Copy
      $vec2-&gt;Interval_Copy($vec1,$offset2,$offset1,$length);

  Interval_Substitute
      $vec2-&gt;Interval_Substitute($vec1,$off2,$len2,$off1,$len1);

  is_empty
      if ($vector-&gt;is_empty())

  is_full
      if ($vector-&gt;is_full())

  equal
      if ($vec1-&gt;equal($vec2))

  Lexicompare (unsigned)
      if ($vec1-&gt;Lexicompare($vec2) == 0)
      if ($vec1-&gt;Lexicompare($vec2) != 0)
      if ($vec1-&gt;Lexicompare($vec2) &lt;  0)
      if ($vec1-&gt;Lexicompare($vec2) &lt;= 0)
      if ($vec1-&gt;Lexicompare($vec2) &gt;  0)
      if ($vec1-&gt;Lexicompare($vec2) &gt;= 0)

  Compare (signed)
      if ($vec1-&gt;Compare($vec2) == 0)
      if ($vec1-&gt;Compare($vec2) != 0)
      if ($vec1-&gt;Compare($vec2) &lt;  0)
      if ($vec1-&gt;Compare($vec2) &lt;= 0)
      if ($vec1-&gt;Compare($vec2) &gt;  0)
      if ($vec1-&gt;Compare($vec2) &gt;= 0)

  to_Hex
      $string = $vector-&gt;to_Hex();

  from_Hex
      $vector-&gt;from_Hex($string);

  to_Bin
      $string = $vector-&gt;to_Bin();

  from_Bin
      $vector-&gt;from_Bin($string);

  to_Dec
      $string = $vector-&gt;to_Dec();

  from_Dec
      $vector-&gt;from_Dec($string);

  to_Enum
      $string = $vector-&gt;to_Enum();  #  e.g. &quot;2,3,5-7,11,13-19&quot;

  from_Enum
      $vector-&gt;from_Enum($string);

  Bit_Off
      $vector-&gt;Bit_Off($index);

  Bit_On
      $vector-&gt;Bit_On($index);

  bit_flip
      $bit = $vector-&gt;bit_flip($index);

  bit_test
  contains
      $bit = $vector-&gt;bit_test($index);
      $bit = $vector-&gt;contains($index);
      if ($vector-&gt;bit_test($index))
      if ($vector-&gt;contains($index))

  Bit_Copy
      $vector-&gt;Bit_Copy($index,$bit);

  LSB (least significant bit)
      $vector-&gt;LSB($bit);

  MSB (most significant bit)
      $vector-&gt;MSB($bit);

  lsb (least significant bit)
      $bit = $vector-&gt;lsb();

  msb (most significant bit)
      $bit = $vector-&gt;msb();

  rotate_left
      $carry = $vector-&gt;rotate_left();

  rotate_right
      $carry = $vector-&gt;rotate_right();

  shift_left
      $carry = $vector-&gt;shift_left($carry);

  shift_right
      $carry = $vector-&gt;shift_right($carry);

  Move_Left
      $vector-&gt;Move_Left($bits);  #  shift left &quot;$bits&quot; positions

  Move_Right
      $vector-&gt;Move_Right($bits);  #  shift right &quot;$bits&quot; positions

  Insert
      $vector-&gt;Insert($offset,$bits);

  Delete
      $vector-&gt;Delete($offset,$bits);

  increment
      $carry = $vector-&gt;increment();

  decrement
      $carry = $vector-&gt;decrement();

  inc
      $overflow = $vec2-&gt;inc($vec1);

  dec
      $overflow = $vec2-&gt;dec($vec1);

  add
      $carry = $vec3-&gt;add($vec1,$vec2,$carry);
      ($carry,$overflow) = $vec3-&gt;add($vec1,$vec2,$carry);

  subtract
      $carry = $vec3-&gt;subtract($vec1,$vec2,$carry);
      ($carry,$overflow) = $vec3-&gt;subtract($vec1,$vec2,$carry);

  Neg
  Negate
      $vec2-&gt;Neg($vec1);
      $vec2-&gt;Negate($vec1);

  Abs
  Absolute
      $vec2-&gt;Abs($vec1);
      $vec2-&gt;Absolute($vec1);

  Sign
      if ($vector-&gt;Sign() == 0)
      if ($vector-&gt;Sign() != 0)
      if ($vector-&gt;Sign() &lt;  0)
      if ($vector-&gt;Sign() &lt;= 0)
      if ($vector-&gt;Sign() &gt;  0)
      if ($vector-&gt;Sign() &gt;= 0)

  Multiply
      $vec3-&gt;Multiply($vec1,$vec2);

  Divide
      $quot-&gt;Divide($vec1,$vec2,$rest);

  GCD (Greatest Common Divisor)
      $vecgcd-&gt;GCD($veca,$vecb);
      $vecgcd-&gt;GCD($vecx,$vecy,$veca,$vecb);

  Power
      $vec3-&gt;Power($vec1,$vec2);

  Block_Store
      $vector-&gt;Block_Store($buffer);

  Block_Read
      $buffer = $vector-&gt;Block_Read();

  Word_Size
      $size = $vector-&gt;Word_Size();  #  number of words in &quot;$vector&quot;

  Word_Store
      $vector-&gt;Word_Store($offset,$word);

  Word_Read
      $word = $vector-&gt;Word_Read($offset);

  Word_List_Store
      $vector-&gt;Word_List_Store(@words);

  Word_List_Read
      @words = $vector-&gt;Word_List_Read();

  Word_Insert
      $vector-&gt;Word_Insert($offset,$count);

  Word_Delete
      $vector-&gt;Word_Delete($offset,$count);

  Chunk_Store
      $vector-&gt;Chunk_Store($chunksize,$offset,$chunk);

  Chunk_Read
      $chunk = $vector-&gt;Chunk_Read($chunksize,$offset);

  Chunk_List_Store
      $vector-&gt;Chunk_List_Store($chunksize,@chunks);

  Chunk_List_Read
      @chunks = $vector-&gt;Chunk_List_Read($chunksize);

  Index_List_Remove
      $vector-&gt;Index_List_Remove(@indices);

  Index_List_Store
      $vector-&gt;Index_List_Store(@indices);

  Index_List_Read
      @indices = $vector-&gt;Index_List_Read();

  Or
  Union
      $vec3-&gt;Or($vec1,$vec2);
      $set3-&gt;Union($set1,$set2);

  And
  Intersection
      $vec3-&gt;And($vec1,$vec2);
      $set3-&gt;Intersection($set1,$set2);

  AndNot
  Difference
      $vec3-&gt;AndNot($vec1,$vec2);
      $set3-&gt;Difference($set1,$set2);

  Xor
  ExclusiveOr
      $vec3-&gt;Xor($vec1,$vec2);
      $set3-&gt;ExclusiveOr($set1,$set2);

  Not
  Complement
      $vec2-&gt;Not($vec1);
      $set2-&gt;Complement($set1);

  subset
      if ($set1-&gt;subset($set2))  #  true if $set1 is subset of $set2

  Norm
      $norm = $set-&gt;Norm();
      $norm = $set-&gt;Norm2();
      $norm = $set-&gt;Norm3();

  Min
      $min = $set-&gt;Min();

  Max
      $max = $set-&gt;Max();

  Multiplication
      $matrix3-&gt;Multiplication($rows3,$cols3,
                      $matrix1,$rows1,$cols1,
                      $matrix2,$rows2,$cols2);

  Product
      $matrix3-&gt;Product($rows3,$cols3,
               $matrix1,$rows1,$cols1,
               $matrix2,$rows2,$cols2);

  Closure
      $matrix-&gt;Closure($rows,$cols);

  Transpose
      $matrix2-&gt;Transpose($rows2,$cols2,$matrix1,$rows1,$cols1);</code></pre>

<h1 id="IMPORTANT-NOTES"><a id="IMPORTANT"></a>IMPORTANT NOTES</h1>

<ul>

<li><p>Method naming conventions</p>

<p>Method names completely in lower case indicate a boolean return value.</p>

<p>(Except for the bit vector constructor method &quot;<code>new()</code>&quot;, of course.)</p>

</li>
<li><p>Boolean values</p>

<p>Boolean values in this module are always a numeric zero (&quot;<code>0</code>&quot;) for &quot;false&quot; and a numeric one (&quot;<code>1</code>&quot;) for &quot;true&quot;.</p>

</li>
<li><p>Negative numbers</p>

<p>All numeric input parameters passed to any of the methods in this module are regarded as being <b>UNSIGNED</b> (as opposed to the contents of the bit vectors themselves, which are usually considered to be <b>SIGNED</b>).</p>

<p>As a consequence, whenever you pass a negative number as an argument to some method of this module, it will be treated as a (usually very large) positive number due to its internal two&#39;s complement binary representation, usually resulting in an &quot;index out of range&quot; error message and program abortion.</p>

</li>
<li><p>Bit order</p>

<p>Note that bit vectors are stored least order bit and least order word first internally.</p>

<p>I.e., bit #0 of any given bit vector corresponds to bit #0 of word #0 in the array of machine words representing the bit vector.</p>

<p>(Where word #0 comes first in memory, i.e., it is stored at the least memory address in the allocated block of memory holding the given bit vector.)</p>

<p>Note however that machine words can be stored least order byte first or last, depending on your system&#39;s implementation.</p>

<p>When you are exporting or importing a whole bit vector at once using the methods &quot;<code>Block_Read()</code>&quot; and &quot;<code>Block_Store()</code>&quot; (the only time in this module where this could make any difference), however, a conversion to and from &quot;least order byte first&quot; order is automatically supplied.</p>

<p>In other words, what &quot;<code>Block_Read()</code>&quot; provides and what &quot;<code>Block_Store()</code>&quot; expects is always in &quot;least order byte first&quot; order, regardless of the order in which words are stored internally on your machine.</p>

<p>This is to make sure that what you export on one machine using &quot;<code>Block_Read()</code>&quot; can always be read in correctly with &quot;<code>Block_Store()</code>&quot; on a different machine.</p>

<p>Note further that whenever bit vectors are converted to and from (binary or hexadecimal) strings, the <b>RIGHTMOST</b> bit is always the <b>LEAST SIGNIFICANT</b> one, and the <b>LEFTMOST</b> bit is always the <b>MOST SIGNIFICANT</b> bit.</p>

<p>This is because in our western culture, numbers are always represented in this way (least significant to most significant digits go from right to left).</p>

<p>Of course this requires an internal reversion of order, which the corresponding conversion methods perform automatically (without any additional overhead, it&#39;s just a matter of starting the internal loop at the bottom or the top end).</p>

</li>
<li><p>&quot;Word&quot; related methods</p>

<p>Note that all methods whose names begin with &quot;<code>Word_</code>&quot; are <b>MACHINE-DEPENDENT</b>!</p>

<p>They depend on the size (number of bits) of an &quot;unsigned int&quot; (C type) on your machine.</p>

<p>Therefore, you should only use these methods if you are <b>ABSOLUTELY CERTAIN</b> that portability of your code is not an issue!</p>

<p>Note that you can use arbitrarily large chunks (i.e., fragments of bit vectors) of up to 32 bits <b>IN A PORTABLE WAY</b> using the methods whose names begin with &quot;<code>Chunk_</code>&quot;.</p>

</li>
<li><p>Chunk sizes</p>

<p>Note that legal chunk sizes for all methods whose names begin with &quot;<code>Chunk_</code>&quot; range from &quot;<code>1</code>&quot; to &quot;<code>Bit::Vector-&gt;Long_Bits();</code>&quot; bits (&quot;<code>0</code>&quot; is <b>NOT</b> allowed!).</p>

<p>In order to make your programs portable, however, you shouldn&#39;t use chunk sizes larger than 32 bits, since this is the minimum size of an &quot;unsigned long&quot; (C type) on all systems, as prescribed by <span style="white-space: nowrap;">ANSI C</span>.</p>

</li>
<li><p>Matching sizes</p>

<p>In general, for methods involving several bit vectors at the same time, all bit vector arguments must have identical sizes (number of bits), or a fatal &quot;size mismatch&quot; error will occur.</p>

<p>Exceptions from this rule are the methods &quot;<code>Concat()</code>&quot;, &quot;<code>Concat_List()</code>&quot;, &quot;<code>Copy()</code>&quot;, &quot;<code>Interval_Copy()</code>&quot; and &quot;<code>Interval_Substitute()</code>&quot;, where no conditions at all are imposed on the size of their bit vector arguments.</p>

<p>In method &quot;<code>Multiply()</code>&quot;, all three bit vector arguments must in principle obey the rule of matching sizes, but the bit vector in which the result of the multiplication is to be stored may be larger than the two bit vector arguments containing the factors for the multiplication.</p>

<p>In method &quot;<code>Power()</code>&quot;, the bit vector for the result must be the same size or greater than the base of the exponentiation term. The exponent can be any size.</p>

</li>
<li><p>Index ranges</p>

<p>All indices for any given bits must lie between &quot;<code>0</code>&quot; and &quot;<code>$vector-&gt;Size()-1</code>&quot;, or a fatal &quot;index out of range&quot; error will occur.</p>

</li>
<li><p>Object persistence</p>

<p>Since version 6.5, &quot;Bit::Vector&quot; objects can be serialized and de-serialized automatically with &quot;Storable&quot;, out-of-the-box, without requiring any further user action for this to work.</p>

<p>This is also true for nested data structures (since version 6.8).</p>

<p>See the <a href="http://man.he.net/man3/Storable">Storable(3)</a> documentation for more details.</p>

</li>
</ul>

<h1 id="DESCRIPTION">DESCRIPTION</h1>

<h2 id="OVERLOADED-OPERATORS1"><a id="OVERLOADED1"></a>OVERLOADED OPERATORS</h2>

<p>See <a href="http://man.he.net/man3/Bit::Vector::Overload">Bit::Vector::Overload(3)</a>.</p>

<h2 id="MORE-STRING-IMPORT/EXPORT1"><a id="MORE1"></a><a id="MORE-STRING-IMPORT-EXPORT1"></a>MORE STRING IMPORT/EXPORT</h2>

<p>See <a href="http://man.he.net/man3/Bit::Vector::String">Bit::Vector::String(3)</a>.</p>

<h2 id="CLASS-METHODS1"><a id="CLASS1"></a>CLASS METHODS</h2>

<ul>

<li><p><code>$version = Bit::Vector-&gt;Version();</code></p>

<p>Returns the current version number of this module.</p>

</li>
<li><p><code>$bits = Bit::Vector-&gt;Word_Bits();</code></p>

<p>Returns the number of bits of an &quot;unsigned int&quot; (C type) on your machine.</p>

<p>(An &quot;unsigned int&quot; is also called a &quot;machine word&quot;, hence the name of this method.)</p>

</li>
<li><p><code>$bits = Bit::Vector-&gt;Long_Bits();</code></p>

<p>Returns the number of bits of an &quot;unsigned long&quot; (C type) on your machine.</p>

</li>
<li><p><code>$vector = Bit::Vector-&gt;new($bits);</code></p>

<p>This is the bit vector constructor method.</p>

<p>Call this method to create a new bit vector containing &quot;<code>$bits</code>&quot; bits (with indices ranging from &quot;<code>0</code>&quot; to &quot;<code>$bits-1</code>&quot;).</p>

<p>Note that - in contrast to previous versions - bit vectors of length zero (i.e., with <code>$bits = 0</code>) are permitted now.</p>

<p>The method returns a reference to the newly created bit vector.</p>

<p>A new bit vector is always initialized so that all bits are cleared (turned off).</p>

<p>An exception will be raised if the method is unable to allocate the necessary memory.</p>

<p>Note that if you specify a negative number for &quot;<code>$bits</code>&quot; it will be interpreted as a large positive number due to its internal two&#39;s complement binary representation.</p>

<p>In such a case, the bit vector constructor method will obediently attempt to create a bit vector of that size, probably resulting in an exception, as explained above.</p>

</li>
<li><p><code>@veclist = Bit::Vector-&gt;new($bits,$count);</code></p>

<p>You can also create more than one bit vector at a time if you specify the optional second parameter &quot;<code>$count</code>&quot;.</p>

<p>The method returns a list of &quot;<code>$count</code>&quot; bit vectors which all have the same number of bits &quot;<code>$bits</code>&quot; (and which are all initialized, i.e., all bits are cleared).</p>

<p>If &quot;<code>$count</code>&quot; is zero, an empty list is returned.</p>

<p>If &quot;<code>$bits</code>&quot; is zero, a list of null-sized bit vectors is returned.</p>

<p>Note again that if you specify a negative number for &quot;<code>$count</code>&quot; it will be interpreted as a large positive number due to its internal two&#39;s complement binary representation.</p>

<p>In such a case, the bit vector constructor method will obediently attempt to create that many bit vectors, probably resulting in an exception (&quot;out of memory&quot;).</p>

</li>
<li><p><code>$vector = Bit::Vector-&gt;new_Hex($bits,$string);</code></p>

<p>This method is an alternative constructor which allows you to create a new bit vector object (with &quot;<code>$bits</code>&quot; bits) and to initialize it all in one go.</p>

<p>The method internally first calls the bit vector constructor method &quot;<code>new()</code>&quot; and then passes the given string to the method &quot;<code>from_Hex()</code>&quot;.</p>

<p>However, this method is more efficient than performing these two steps separately: First because in this method, the memory area occupied by the new bit vector is not initialized to zeros (which is pointless in this case), and second because it saves you from the associated overhead of one additional method invocation.</p>

<p>An exception will be raised if the necessary memory cannot be allocated (see the description of the method &quot;<code>new()</code>&quot; immediately above for possible causes) or if the given string cannot be converted successfully (see the description of the method &quot;<code>from_Hex()</code>&quot; further below for details).</p>

<p>In the latter case, the memory occupied by the new bit vector is released first (i.e., &quot;free&quot;d) before the exception is actually raised.</p>

</li>
<li><p><code>$vector = Bit::Vector-&gt;new_Bin($bits,$string);</code></p>

<p>This method is an alternative constructor which allows you to create a new bit vector object (with &quot;<code>$bits</code>&quot; bits) and to initialize it all in one go.</p>

<p>The method internally first calls the bit vector constructor method &quot;<code>new()</code>&quot; and then passes the given string to the method &quot;<code>from_Bin()</code>&quot;.</p>

<p>However, this method is more efficient than performing these two steps separately: First because in this method, the memory area occupied by the new bit vector is not initialized to zeros (which is pointless in this case), and second because it saves you from the associated overhead of one additional method invocation.</p>

<p>An exception will be raised if the necessary memory cannot be allocated (see the description of the method &quot;<code>new()</code>&quot; above for possible causes) or if the given string cannot be converted successfully (see the description of the method &quot;<code>from_Bin()</code>&quot; further below for details).</p>

<p>In the latter case, the memory occupied by the new bit vector is released first (i.e., &quot;free&quot;d) before the exception is actually raised.</p>

</li>
<li><p><code>$vector = Bit::Vector-&gt;new_Dec($bits,$string);</code></p>

<p>This method is an alternative constructor which allows you to create a new bit vector object (with &quot;<code>$bits</code>&quot; bits) and to initialize it all in one go.</p>

<p>The method internally first calls the bit vector constructor method &quot;<code>new()</code>&quot; and then passes the given string to the method &quot;<code>from_Dec()</code>&quot;.</p>

<p>However, this method is more efficient than performing these two steps separately: First because in this method, &quot;<code>new()</code>&quot; does not initialize the memory area occupied by the new bit vector with zeros (which is pointless in this case, because &quot;<code>from_Dec()</code>&quot; will do it anyway), and second because it saves you from the associated overhead of one additional method invocation.</p>

<p>An exception will be raised if the necessary memory cannot be allocated (see the description of the method &quot;<code>new()</code>&quot; above for possible causes) or if the given string cannot be converted successfully (see the description of the method &quot;<code>from_Dec()</code>&quot; further below for details).</p>

<p>In the latter case, the memory occupied by the new bit vector is released first (i.e., &quot;free&quot;d) before the exception is actually raised.</p>

</li>
<li><p><code>$vector = Bit::Vector-&gt;new_Enum($bits,$string);</code></p>

<p>This method is an alternative constructor which allows you to create a new bit vector object (with &quot;<code>$bits</code>&quot; bits) and to initialize it all in one go.</p>

<p>The method internally first calls the bit vector constructor method &quot;<code>new()</code>&quot; and then passes the given string to the method &quot;<code>from_Enum()</code>&quot;.</p>

<p>However, this method is more efficient than performing these two steps separately: First because in this method, &quot;<code>new()</code>&quot; does not initialize the memory area occupied by the new bit vector with zeros (which is pointless in this case, because &quot;<code>from_Enum()</code>&quot; will do it anyway), and second because it saves you from the associated overhead of one additional method invocation.</p>

<p>An exception will be raised if the necessary memory cannot be allocated (see the description of the method &quot;<code>new()</code>&quot; above for possible causes) or if the given string cannot be converted successfully (see the description of the method &quot;<code>from_Enum()</code>&quot; further below for details).</p>

<p>In the latter case, the memory occupied by the new bit vector is released first (i.e., &quot;free&quot;d) before the exception is actually raised.</p>

</li>
<li><p><code>$vector = Bit::Vector-&gt;Concat_List(@vectors);</code></p>

<p>This method creates a new vector containing all bit vectors from the argument list in concatenated form.</p>

<p>The argument list may contain any number of arguments (including zero); the only condition is that all arguments must be bit vectors.</p>

<p>There is no condition concerning the length (in number of bits) of these arguments.</p>

<p>The vectors from the argument list are not changed in any way.</p>

<p>If the argument list is empty or if all arguments have length zero, the resulting bit vector will also have length zero.</p>

<p>Note that the <b>RIGHTMOST</b> bit vector from the argument list will become the <b>LEAST</b> significant part of the resulting bit vector, and the <b>LEFTMOST</b> bit vector from the argument list will become the <b>MOST</b> significant part of the resulting bit vector.</p>

</li>
</ul>

<h2 id="OBJECT-METHODS1"><a id="OBJECT1"></a>OBJECT METHODS</h2>

<ul>

<li><p><code>$vec2 = $vec1-&gt;new($bits);</code></p>

<p><code>@veclist = $vec-&gt;new($bits);</code></p>

<p>This is an alternative way of calling the bit vector constructor method.</p>

<p>Vector &quot;<code>$vec1</code>&quot; (or &quot;<code>$vec</code>&quot;) is not affected by this, it just serves as an anchor for the method invocation mechanism.</p>

<p>In fact <b>ALL</b> class methods in this module can be called this way, even though this is probably considered to be &quot;politically incorrect&quot; by OO (&quot;object-orientation&quot;) aficionados. ;-)</p>

<p>So even if you are too lazy to type &quot;<code>Bit::Vector-&gt;</code>&quot; instead of &quot;<code>$vec1-&gt;</code>&quot; (and even though laziness is - allegedly - a programmer&#39;s virtue <code>:-)</code>), maybe it is better not to use this feature if you don&#39;t want to get booed at. ;-)</p>

</li>
<li><p><code>$vec2 = $vec1-&gt;Shadow();</code></p>

<p>Creates a <b>NEW</b> bit vector &quot;<code>$vec2</code>&quot; of the <b>SAME SIZE</b> as &quot;<code>$vec1</code>&quot; but which is <b>EMPTY</b>.</p>

<p>Just like a shadow that has the same shape as the object it originates from, but is flat and has no volume, i.e., contains nothing.</p>

</li>
<li><p><code>$vec2 = $vec1-&gt;Clone();</code></p>

<p>Creates a <b>NEW</b> bit vector &quot;<code>$vec2</code>&quot; of the <b>SAME SIZE</b> as &quot;<code>$vec1</code>&quot; which is an <b>EXACT COPY</b> of &quot;<code>$vec1</code>&quot;.</p>

</li>
<li><p><code>$vector = $vec1-&gt;Concat($vec2);</code></p>

<p>This method returns a new bit vector object which is the result of the concatenation of the contents of &quot;<code>$vec1</code>&quot; and &quot;<code>$vec2</code>&quot;.</p>

<p>Note that the contents of &quot;<code>$vec1</code>&quot; become the <b>MOST</b> significant part of the resulting bit vector, and &quot;<code>$vec2</code>&quot; the <b>LEAST</b> significant part.</p>

<p>If both bit vector arguments have length zero, the resulting bit vector will also have length zero.</p>

</li>
<li><p><code>$vector = $vec1-&gt;Concat_List($vec2,$vec3,...);</code></p>

<p>This is an alternative way of calling this (class) method as an object method.</p>

<p>The method returns a new bit vector object which is the result of the concatenation of the contents of <code>$vec1 . $vec2 . $vec3 . ...</code></p>

<p>See the section &quot;class methods&quot; above for a detailed description of this method.</p>

<p>Note that the argument list may be empty and that all arguments must be bit vectors if it isn&#39;t.</p>

</li>
<li><p><code>$bits = $vector-&gt;Size();</code></p>

<p>Returns the size (number of bits) the given vector was created with (or &quot;<code>Resize()</code>&quot;d to).</p>

</li>
<li><p><code>$vector-&gt;Resize($bits);</code></p>

<p>Changes the size of the given vector to the specified number of bits.</p>

<p>This method allows you to change the size of an existing bit vector, preserving as many bits from the old vector as will fit into the new one (i.e., all bits with indices smaller than the minimum of the sizes of both vectors, old and new).</p>

<p>If the number of machine words needed to store the new vector is smaller than or equal to the number of words needed to store the old vector, the memory allocated for the old vector is reused for the new one, and only the relevant book-keeping information is adjusted accordingly.</p>

<p>This means that even if the number of bits increases, new memory is not necessarily being allocated (i.e., if the old and the new number of bits fit into the same number of machine words).</p>

<p>If the number of machine words needed to store the new vector is greater than the number of words needed to store the old vector, new memory is allocated for the new vector, the old vector is copied to the new one, the remaining bits in the new vector are cleared (turned off) and the old vector is deleted, i.e., the memory that was allocated for it is released.</p>

<p>(An exception will be raised if the method is unable to allocate the necessary memory for the new vector.)</p>

<p>As a consequence, if you decrease the size of a given vector so that it will use fewer machine words, and increase it again later so that it will use more words than immediately before but still less than the original vector, new memory will be allocated anyway because the information about the size of the original vector is lost whenever you resize it.</p>

<p>Note also that if you specify a negative number for &quot;<code>$bits</code>&quot; it will be interpreted as a large positive number due to its internal two&#39;s complement binary representation.</p>

<p>In such a case, &quot;Resize()&quot; will obediently attempt to create a bit vector of that size, probably resulting in an exception, as explained above.</p>

<p>Finally, note that - in contrast to previous versions - resizing a bit vector to a size of zero bits (length zero) is now permitted.</p>

</li>
<li><p><code>$vec2-&gt;Copy($vec1);</code></p>

<p>Copies the contents of bit vector &quot;<code>$vec1</code>&quot; to bit vector &quot;<code>$vec2</code>&quot;.</p>

<p>The previous contents of bit vector &quot;<code>$vec2</code>&quot; get overwritten, i.e., are lost.</p>

<p>Both vectors must exist beforehand, i.e., this method does not <b>CREATE</b> any new bit vector object.</p>

<p>The two vectors may be of any size.</p>

<p>If the source bit vector is larger than the target, this method will copy as much of the least significant bits of the source vector as will fit into the target vector, thereby discarding any extraneous most significant bits.</p>

<p>BEWARE that this causes a brutal cutoff in the middle of your data, and it will also leave you with an almost unpredictable sign if subsequently the number in the target vector is going to be interpreted as a number! (You have been warned!)</p>

<p>If the target bit vector is larger than the source, this method fills up the remaining most significant bits in the target bit vector with either 0&#39;s or 1&#39;s, depending on the sign (= the most significant bit) of the source bit vector. This is also known as &quot;sign extension&quot;.</p>

<p>This makes it possible to copy numbers from a smaller bit vector into a larger one while preserving the number&#39;s absolute value as well as its sign (due to the two&#39;s complement binary representation of numbers).</p>

</li>
<li><p><code>$vector-&gt;Empty();</code></p>

<p>Clears all bits in the given vector.</p>

</li>
<li><p><code>$vector-&gt;Fill();</code></p>

<p>Sets all bits in the given vector.</p>

</li>
<li><p><code>$vector-&gt;Flip();</code></p>

<p>Flips (i.e., complements) all bits in the given vector.</p>

</li>
<li><p><code>$vector-&gt;Primes();</code></p>

<p>Clears the given bit vector and sets all bits whose indices are prime numbers.</p>

<p>This method uses the algorithm known as the &quot;Sieve of Erathostenes&quot; internally.</p>

</li>
<li><p><code>$vec2-&gt;Reverse($vec1);</code></p>

<p>This method copies the given vector &quot;<code>$vec1</code>&quot; to the vector &quot;<code>$vec2</code>&quot;, thereby reversing the order of all bits.</p>

<p>I.e., the least significant bit of &quot;<code>$vec1</code>&quot; becomes the most significant bit of &quot;<code>$vec2</code>&quot;, whereas the most significant bit of &quot;<code>$vec1</code>&quot; becomes the least significant bit of &quot;<code>$vec2</code>&quot;, and so forth for all bits in between.</p>

<p>Note that in-place processing is also possible, i.e., &quot;<code>$vec1</code>&quot; and &quot;<code>$vec2</code>&quot; may be identical.</p>

<p>(Internally, this is the same as <code>$vec1-&gt;Interval_Reverse(0,$vec1-&gt;Size()-1);</code>.)</p>

</li>
<li><p><code>$vector-&gt;Interval_Empty($min,$max);</code></p>

<p>Clears all bits in the interval <code>[$min..$max]</code> (including both limits) in the given vector.</p>

<p>&quot;<code>$min</code>&quot; and &quot;<code>$max</code>&quot; may have the same value; this is the same as clearing a single bit with &quot;<code>Bit_Off()</code>&quot; (but less efficient).</p>

<p>Note that <code>$vector-&gt;Interval_Empty(0,$vector-&gt;Size()-1);</code> is the same as <code>$vector-&gt;Empty();</code> (but less efficient).</p>

</li>
<li><p><code>$vector-&gt;Interval_Fill($min,$max);</code></p>

<p>Sets all bits in the interval <code>[$min..$max]</code> (including both limits) in the given vector.</p>

<p>&quot;<code>$min</code>&quot; and &quot;<code>$max</code>&quot; may have the same value; this is the same as setting a single bit with &quot;<code>Bit_On()</code>&quot; (but less efficient).</p>

<p>Note that <code>$vector-&gt;Interval_Fill(0,$vector-&gt;Size()-1);</code> is the same as <code>$vector-&gt;Fill();</code> (but less efficient).</p>

</li>
<li><p><code>$vector-&gt;Interval_Flip($min,$max);</code></p>

<p>Flips (i.e., complements) all bits in the interval <code>[$min..$max]</code> (including both limits) in the given vector.</p>

<p>&quot;<code>$min</code>&quot; and &quot;<code>$max</code>&quot; may have the same value; this is the same as flipping a single bit with &quot;<code>bit_flip()</code>&quot; (but less efficient).</p>

<p>Note that <code>$vector-&gt;Interval_Flip(0,$vector-&gt;Size()-1);</code> is the same as <code>$vector-&gt;Flip();</code> and <code>$vector-&gt;Complement($vector);</code> (but less efficient).</p>

</li>
<li><p><code>$vector-&gt;Interval_Reverse($min,$max);</code></p>

<p>Reverses the order of all bits in the interval <code>[$min..$max]</code> (including both limits) in the given vector.</p>

<p>I.e., bits &quot;<code>$min</code>&quot; and &quot;<code>$max</code>&quot; swap places, and so forth for all bits in between.</p>

<p>&quot;<code>$min</code>&quot; and &quot;<code>$max</code>&quot; may have the same value; this has no effect whatsoever, though.</p>

</li>
<li><p><code>if (($min,$max) = $vector-&gt;Interval_Scan_inc($start))</code></p>

<p>Returns the minimum and maximum indices of the next contiguous block of set bits (i.e., bits in the &quot;on&quot; state).</p>

<p>The search starts at index &quot;<code>$start</code>&quot; (i.e., <code>&quot;$min&quot; &gt;= &quot;$start&quot;</code>) and proceeds upwards (i.e., <code>&quot;$max&quot; &gt;= &quot;$min&quot;</code>), thus repeatedly increments the search pointer &quot;<code>$start</code>&quot; (internally).</p>

<p>Note though that the contents of the variable (or scalar literal value) &quot;<code>$start</code>&quot; is <b>NOT</b> altered. I.e., you have to set it to the desired value yourself prior to each call to &quot;<code>Interval_Scan_inc()</code>&quot; (see also the example given below).</p>

<p>Actually, the bit vector is not searched bit by bit, but one machine word at a time, in order to speed up execution (which means that this method is quite efficient).</p>

<p>An empty list is returned if no such block can be found.</p>

<p>Note that a single set bit (surrounded by cleared bits) is a valid block by this definition. In that case the return values for &quot;<code>$min</code>&quot; and &quot;<code>$max</code>&quot; are the same.</p>

<p>Typical use:</p>

<pre><code>    $start = 0;
    while (($start &lt; $vector-&gt;Size()) &amp;&amp;
        (($min,$max) = $vector-&gt;Interval_Scan_inc($start)))
    {
        $start = $max + 2;

        # do something with $min and $max
    }</code></pre>

</li>
<li><p><code>if (($min,$max) = $vector-&gt;Interval_Scan_dec($start))</code></p>

<p>Returns the minimum and maximum indices of the next contiguous block of set bits (i.e., bits in the &quot;on&quot; state).</p>

<p>The search starts at index &quot;<code>$start</code>&quot; (i.e., <code>&quot;$max&quot; &lt;= &quot;$start&quot;</code>) and proceeds downwards (i.e., <code>&quot;$min&quot; &lt;= &quot;$max&quot;</code>), thus repeatedly decrements the search pointer &quot;<code>$start</code>&quot; (internally).</p>

<p>Note though that the contents of the variable (or scalar literal value) &quot;<code>$start</code>&quot; is <b>NOT</b> altered. I.e., you have to set it to the desired value yourself prior to each call to &quot;<code>Interval_Scan_dec()</code>&quot; (see also the example given below).</p>

<p>Actually, the bit vector is not searched bit by bit, but one machine word at a time, in order to speed up execution (which means that this method is quite efficient).</p>

<p>An empty list is returned if no such block can be found.</p>

<p>Note that a single set bit (surrounded by cleared bits) is a valid block by this definition. In that case the return values for &quot;<code>$min</code>&quot; and &quot;<code>$max</code>&quot; are the same.</p>

<p>Typical use:</p>

<pre><code>    $start = $vector-&gt;Size() - 1;
    while (($start &gt;= 0) &amp;&amp;
        (($min,$max) = $vector-&gt;Interval_Scan_dec($start)))
    {
        $start = $min - 2;

        # do something with $min and $max
    }</code></pre>

</li>
<li><p><code>$vec2-&gt;Interval_Copy($vec1,$offset2,$offset1,$length);</code></p>

<p>This method allows you to copy a stretch of contiguous bits (starting at any position &quot;<code>$offset1</code>&quot; you choose, with a length of &quot;<code>$length</code>&quot; bits) from a given &quot;source&quot; bit vector &quot;<code>$vec1</code>&quot; to another position &quot;<code>$offset2</code>&quot; in a &quot;target&quot; bit vector &quot;<code>$vec2</code>&quot;.</p>

<p>Note that the two bit vectors &quot;<code>$vec1</code>&quot; and &quot;<code>$vec2</code>&quot; do <b>NOT</b> need to have the same (matching) size!</p>

<p>Consequently, any of the two terms &quot;<code>$offset1 + $length</code>&quot; and &quot;<code>$offset2 + $length</code>&quot; (or both) may exceed the actual length of its corresponding bit vector (&quot;<code>$vec1-&gt;Size()</code>&quot; and &quot;<code>$vec2-&gt;Size()</code>&quot;, respectively).</p>

<p>In such a case, the &quot;<code>$length</code>&quot; parameter is automatically reduced internally so that both terms above are bounded by the number of bits of their corresponding bit vector.</p>

<p>This may even result in a length of zero, in which case nothing is copied at all.</p>

<p>(Of course the value of the &quot;<code>$length</code>&quot; parameter, supplied by you in the initial method call, may also be zero right from the start!)</p>

<p>Note also that &quot;<code>$offset1</code>&quot; and &quot;<code>$offset2</code>&quot; must lie within the range &quot;<code>0</code>&quot; and, respectively, &quot;<code>$vec1-&gt;Size()-1</code>&quot; or &quot;<code>$vec2-&gt;Size()-1</code>&quot;, or a fatal &quot;offset out of range&quot; error will occur.</p>

<p>Note further that &quot;<code>$vec1</code>&quot; and &quot;<code>$vec2</code>&quot; may be identical, i.e., you may copy a stretch of contiguous bits from one part of a given bit vector to another part.</p>

<p>The source and the target interval may even overlap, in which case the copying is automatically performed in ascending or descending order (depending on the direction of the copy - downwards or upwards in the bit vector, respectively) to handle this situation correctly, i.e., so that no bits are being overwritten before they have been copied themselves.</p>

</li>
<li><p><code>$vec2-&gt;Interval_Substitute($vec1,$off2,$len2,$off1,$len1);</code></p>

<p>This method is (roughly) the same for bit vectors (i.e., arrays of booleans) as what the &quot;splice&quot; function in Perl is for lists (i.e., arrays of scalars).</p>

<p>(See <a href="functions/CORE.html#splice">&quot;splice&quot; in perlfunc</a> for more details about this function.)</p>

<p>The method allows you to substitute a stretch of contiguous bits (defined by a position (offset) &quot;<code>$off1</code>&quot; and a length of &quot;<code>$len1</code>&quot; bits) from a given &quot;source&quot; bit vector &quot;<code>$vec1</code>&quot; for a different stretch of contiguous bits (defined by a position (offset) &quot;<code>$off2</code>&quot; and a length of &quot;<code>$len2</code>&quot; bits) in another, &quot;target&quot; bit vector &quot;<code>$vec2</code>&quot;.</p>

<p>Note that the two bit vectors &quot;<code>$vec1</code>&quot; and &quot;<code>$vec2</code>&quot; do <b>NOT</b> need to have the same (matching) size!</p>

<p>Note further that &quot;<code>$off1</code>&quot; and &quot;<code>$off2</code>&quot; must lie within the range &quot;<code>0</code>&quot; and, respectively, &quot;<code>$vec1-&gt;Size()</code>&quot; or &quot;<code>$vec2-&gt;Size()</code>&quot;, or a fatal &quot;offset out of range&quot; error will occur.</p>

<p>Alert readers will have noticed that these upper limits are <b>NOT</b> &quot;<code>$vec1-&gt;Size()-1</code>&quot; and &quot;<code>$vec2-&gt;Size()-1</code>&quot;, as they would be for any other method in this module, but that these offsets may actually point to one position <b>PAST THE END</b> of the corresponding bit vector.</p>

<p>This is necessary in order to make it possible to <b>APPEND</b> a given stretch of bits to the target bit vector instead of <b>REPLACING</b> something in it.</p>

<p>For reasons of symmetry and generality, the same applies to the offset in the source bit vector, even though such an offset (one position past the end of the bit vector) does not serve any practical purpose there (but does not cause any harm either).</p>

<p>(Actually this saves you from the need of testing for this special case, in certain circumstances.)</p>

<p>Note that whenever the term &quot;<code>$off1 + $len1</code>&quot; exceeds the size &quot;<code>$vec1-&gt;Size()</code>&quot; of bit vector &quot;<code>$vec1</code>&quot; (or if &quot;<code>$off2 + $len2</code>&quot; exceeds &quot;<code>$vec2-&gt;Size()</code>&quot;), the corresponding length (&quot;<code>$len1</code>&quot; or &quot;<code>$len2</code>&quot;, respectively) is automatically reduced internally so that &quot;<code>$off1 + $len1 &lt;= $vec1-&gt;Size()</code>&quot; (and &quot;<code>$off2 + $len2 &lt;= $vec2-&gt;Size()</code>&quot;) holds.</p>

<p>(Note that this does <b>NOT</b> alter the intended result, even though this may seem counter-intuitive at first!)</p>

<p>This may even result in a length (&quot;<code>$len1</code>&quot; or &quot;<code>$len2</code>&quot;) of zero.</p>

<p>A length of zero for the interval in the <b>SOURCE</b> bit vector (&quot;<code>$len1 == 0</code>&quot;) means that the indicated stretch of bits in the target bit vector (starting at position &quot;<code>$off2</code>&quot;) is to be replaced by <b>NOTHING</b>, i.e., is to be <b>DELETED</b>.</p>

<p>A length of zero for the interval in the <b>TARGET</b> bit vector (&quot;<code>$len2</code> == 0&quot;) means that <b>NOTHING</b> is replaced, and that the stretch of bits from the source bit vector is simply <b>INSERTED</b> into the target bit vector at the indicated position (&quot;<code>$off2</code>&quot;).</p>

<p>If both length parameters are zero, nothing is done at all.</p>

<p>Note that in contrast to any other method in this module (especially &quot;<code>Interval_Copy()</code>&quot;, &quot;<code>Insert()</code>&quot; and &quot;<code>Delete()</code>&quot;), this method <b>IMPLICITLY</b> and <b>AUTOMATICALLY</b> adapts the length of the resulting bit vector as needed, as given by</p>

<pre><code>        $size = $vec2-&gt;Size();   #  before
        $size += $len1 - $len2;  #  after</code></pre>

<p>(The only other method in this module that changes the size of a bit vector is the method &quot;<code>Resize()</code>&quot;.)</p>

<p>In other words, replacing a given interval of bits in the target bit vector with a longer or shorter stretch of bits from the source bit vector, or simply inserting (&quot;<code>$len2 == 0</code>&quot;) a stretch of bits into or deleting (&quot;<code>$len1 == 0</code>&quot;) an interval of bits from the target bit vector will automatically increase or decrease, respectively, the size of the target bit vector accordingly.</p>

<p>For the sake of generality, this may even result in a bit vector with a size of zero (containing no bits at all).</p>

<p>This is also the reason why bit vectors of length zero are permitted in this module in the first place, starting with version 5.0.</p>

<p>Finally, note that &quot;<code>$vec1</code>&quot; and &quot;<code>$vec2</code>&quot; may be identical, i.e., in-place processing is possible.</p>

<p>(If you think about that for a while or if you look at the code, you will see that this is far from trivial!)</p>

</li>
<li><p><code>if ($vector-&gt;is_empty())</code></p>

<p>Tests whether the given bit vector is empty, i.e., whether <b>ALL</b> of its bits are cleared (in the &quot;off&quot; state).</p>

<p>In &quot;big integer&quot; arithmetic, this is equivalent to testing whether the number stored in the bit vector is zero (&quot;<code>0</code>&quot;).</p>

<p>Returns &quot;true&quot; (&quot;<code>1</code>&quot;) if the bit vector is empty and &quot;false&quot; (&quot;<code>0</code>&quot;) otherwise.</p>

<p>Note that this method also returns &quot;true&quot; (&quot;<code>1</code>&quot;) if the given bit vector has a length of zero, i.e., if it contains no bits at all.</p>

</li>
<li><p><code>if ($vector-&gt;is_full())</code></p>

<p>Tests whether the given bit vector is full, i.e., whether <b>ALL</b> of its bits are set (in the &quot;on&quot; state).</p>

<p>In &quot;big integer&quot; arithmetic, this is equivalent to testing whether the number stored in the bit vector is minus one (&quot;-1&quot;).</p>

<p>Returns &quot;true&quot; (&quot;<code>1</code>&quot;) if the bit vector is full and &quot;false&quot; (&quot;<code>0</code>&quot;) otherwise.</p>

<p>If the given bit vector has a length of zero (i.e., if it contains no bits at all), this method returns &quot;false&quot; (&quot;<code>0</code>&quot;).</p>

</li>
<li><p><code>if ($vec1-&gt;equal($vec2))</code></p>

<p>Tests the two given bit vectors for equality.</p>

<p>Returns &quot;true&quot; (&quot;<code>1</code>&quot;) if the two bit vectors are exact copies of one another and &quot;false&quot; (&quot;<code>0</code>&quot;) otherwise.</p>

</li>
<li><p><code>$cmp = $vec1-&gt;Lexicompare($vec2);</code></p>

<p>Compares the two given bit vectors, which are regarded as <b>UNSIGNED</b> numbers in binary representation.</p>

<p>The method returns &quot;<code>-1</code>&quot; if the first bit vector is smaller than the second bit vector, &quot;<code>0</code>&quot; if the two bit vectors are exact copies of one another and &quot;<code>1</code>&quot; if the first bit vector is greater than the second bit vector.</p>

</li>
<li><p><code>$cmp = $vec1-&gt;Compare($vec2);</code></p>

<p>Compares the two given bit vectors, which are regarded as <b>SIGNED</b> numbers in binary representation.</p>

<p>The method returns &quot;<code>-1</code>&quot; if the first bit vector is smaller than the second bit vector, &quot;<code>0</code>&quot; if the two bit vectors are exact copies of one another and &quot;<code>1</code>&quot; if the first bit vector is greater than the second bit vector.</p>

</li>
<li><p><code>$string = $vector-&gt;to_Hex();</code></p>

<p>Returns a hexadecimal string representing the given bit vector.</p>

<p>Note that this representation is quite compact, in that it only needs at most twice the number of bytes needed to store the bit vector itself, internally.</p>

<p>Note also that since a hexadecimal digit is always worth four bits, the length of the resulting string is always a multiple of four bits, regardless of the true length (in bits) of the given bit vector.</p>

<p>Finally, note that the <b>LEAST</b> significant hexadecimal digit is located at the <b>RIGHT</b> end of the resulting string, and the <b>MOST</b> significant digit at the <b>LEFT</b> end.</p>

</li>
<li><p><code>$vector-&gt;from_Hex($string);</code></p>

<p>Allows to read in the contents of a bit vector from a hexadecimal string, such as returned by the method &quot;<code>to_Hex()</code>&quot; (see above).</p>

<p>Remember that the least significant bits are always to the right of a hexadecimal string, and the most significant bits to the left. Therefore, the string is actually read in from right to left while the bit vector is filled accordingly, 4 bits at a time, starting with the least significant bits and going upward to the most significant bits.</p>

<p>If the given string contains less hexadecimal digits than are needed to completely fill the given bit vector, the remaining (most significant) bits are all cleared.</p>

<p>This also means that, even if the given string does not contain enough digits to completely fill the given bit vector, the previous contents of the bit vector are erased completely.</p>

<p>If the given string is longer than it needs to fill the given bit vector, the superfluous characters are simply ignored.</p>

<p>(In fact they are ignored completely - they are not even checked for proper syntax. See also below for more about that.)</p>

<p>This behaviour is intentional so that you may read in the string representing one bit vector into another bit vector of different size, i.e., as much of it as will fit.</p>

<p>If during the process of reading the given string any character is encountered which is not a hexadecimal digit, a fatal syntax error ensues (&quot;input string syntax error&quot;).</p>

</li>
<li><p><code>$string = $vector-&gt;to_Bin();</code></p>

<p>Returns a binary string representing the given bit vector.</p>

<p>Example:</p>

<pre><code>  $vector = Bit::Vector-&gt;new(8);
  $vector-&gt;Primes();
  $string = $vector-&gt;to_Bin();
  print &quot;&#39;$string&#39;\n&quot;;</code></pre>

<p>This prints:</p>

<pre><code>  &#39;10101100&#39;</code></pre>

<p>(Bits #7, #5, #3 and #2 are set.)</p>

<p>Note that the <b>LEAST</b> significant bit is located at the <b>RIGHT</b> end of the resulting string, and the <b>MOST</b> significant bit at the <b>LEFT</b> end.</p>

</li>
<li><p><code>$vector-&gt;from_Bin($string);</code></p>

<p>This method allows you to read in the contents of a bit vector from a binary string, such as returned by the method &quot;<code>to_Bin()</code>&quot; (see above).</p>

<p>Note that this method assumes that the <b>LEAST</b> significant bit is located at the <b>RIGHT</b> end of the binary string, and the <b>MOST</b> significant bit at the <b>LEFT</b> end. Therefore, the string is actually read in from right to left while the bit vector is filled accordingly, one bit at a time, starting with the least significant bit and going upward to the most significant bit.</p>

<p>If the given string contains less binary digits (&quot;<code>0</code>&quot; and &quot;<code>1</code>&quot;) than are needed to completely fill the given bit vector, the remaining (most significant) bits are all cleared.</p>

<p>This also means that, even if the given string does not contain enough digits to completely fill the given bit vector, the previous contents of the bit vector are erased completely.</p>

<p>If the given string is longer than it needs to fill the given bit vector, the superfluous characters are simply ignored.</p>

<p>(In fact they are ignored completely - they are not even checked for proper syntax. See also below for more about that.)</p>

<p>This behaviour is intentional so that you may read in the string representing one bit vector into another bit vector of different size, i.e., as much of it as will fit.</p>

<p>If during the process of reading the given string any character is encountered which is not either &quot;<code>0</code>&quot; or &quot;<code>1</code>&quot;, a fatal syntax error ensues (&quot;input string syntax error&quot;).</p>

</li>
<li><p><code>$string = $vector-&gt;to_Dec();</code></p>

<p>This method returns a string representing the contents of the given bit vector converted to decimal (base <code>10</code>).</p>

<p>Note that this method assumes the given bit vector to be <b>SIGNED</b> (and to contain a number in two&#39;s complement binary representation).</p>

<p>Consequently, whenever the most significant bit of the given bit vector is set, the number stored in it is regarded as being <b>NEGATIVE</b>.</p>

<p>The resulting string can be fed into &quot;<code>from_Dec()</code>&quot; (see below) in order to copy the contents of this bit vector to another one (or to restore the contents of this one). This is not advisable, though, since this would be very inefficient (there are much more efficient methods for storing and copying bit vectors in this module).</p>

<p>Note that such conversion from binary to decimal is inherently slow since the bit vector has to be repeatedly divided by <code>10</code> with remainder until the quotient becomes <code>0</code> (each remainder in turn represents a single decimal digit of the resulting string).</p>

<p>This is also true for the implementation of this method in this module, even though a considerable effort has been made to speed it up: instead of repeatedly dividing by <code>10</code>, the bit vector is repeatedly divided by the largest power of <code>10</code> that will fit into a machine word. The remainder is then repeatedly divided by <code>10</code> using only machine word arithmetics, which is much faster than dividing the whole bit vector (&quot;divide and rule&quot; principle).</p>

<p>According to my own measurements, this resulted in an 8-fold speed increase over the straightforward approach.</p>

<p>Still, conversion to decimal should be used only where absolutely necessary.</p>

<p>Keep the resulting string stored in some variable if you need it again, instead of converting the bit vector all over again.</p>

<p>Beware that if you set the configuration for overloaded operators to &quot;output=decimal&quot;, this method will be called for every bit vector enclosed in double quotes!</p>

</li>
<li><p><code>$vector-&gt;from_Dec($string);</code></p>

<p>This method allows you to convert a given decimal number, which may be positive or negative, into two&#39;s complement binary representation, which is then stored in the given bit vector.</p>

<p>The decimal number should always be provided as a string, to avoid possible truncation (due to the limited precision of integers in Perl) or formatting (due to Perl&#39;s use of scientific notation for large numbers), which would lead to errors.</p>

<p>If the binary representation of the given decimal number is too big to fit into the given bit vector (if the given bit vector does not contain enough bits to hold it), a fatal &quot;numeric overflow error&quot; occurs.</p>

<p>If the input string contains other characters than decimal digits (<code>0-9</code>) and an optional leading sign (&quot;<code>+</code>&quot; or &quot;<code>-</code>&quot;), a fatal &quot;input string syntax error&quot; occurs.</p>

<p>Beware that large positive numbers which cause the most significant bit to be set (e.g. &quot;255&quot; in a bit vector with 8 bits) will be printed as negative numbers when converted back to decimal using the method &quot;to_Dec()&quot; (e.g. &quot;-1&quot;, in our example), because numbers with the most significant bit set are considered to be negative in two&#39;s complement binary representation.</p>

<p>Note also that while it is possible to thusly enter negative numbers as large positive numbers (e.g. &quot;255&quot; for &quot;-1&quot; in a bit vector with 8 bits), the contrary isn&#39;t, i.e., you cannot enter &quot;-255&quot; for &quot;+1&quot;, in our example. A fatal &quot;numeric overflow error&quot; will occur if you try to do so.</p>

<p>If possible program abortion is unwanted or intolerable, use &quot;<code>eval</code>&quot;, like this:</p>

<pre><code>  eval { $vector-&gt;from_Dec(&quot;1152921504606846976&quot;); };
  if ($@)
  {
      # an error occurred
  }</code></pre>

<p>There are four possible error messages:</p>

<pre><code>  if ($@ =~ /item is not a string/)

  if ($@ =~ /input string syntax error/)

  if ($@ =~ /numeric overflow error/)

  if ($@ =~ /unable to allocate memory/)</code></pre>

<p>Note that the conversion from decimal to binary is costly in terms of processing time, since a lot of multiplications have to be carried out (in principle, each decimal digit must be multiplied with the binary representation of the power of <code>10</code> corresponding to its position in the decimal number, i.e., 1, 10, 100, 1000, 10000 and so on).</p>

<p>This is not as time consuming as the opposite conversion, from binary to decimal (where successive divisions have to be carried out, which are even more expensive than multiplications), but still noticeable.</p>

<p>Again (as in the case of &quot;<code>to_Dec()</code>&quot;), the implementation of this method in this module uses the principle of &quot;divide and rule&quot; in order to speed up the conversion, i.e., as many decimal digits as possible are first accumulated (converted) in a machine word and only then stored in the given bit vector.</p>

<p>Even so, use this method only where absolutely necessary if speed is an important consideration in your application.</p>

<p>Beware that if you set the configuration for overloaded operators to &quot;input=decimal&quot;, this method will be called for every scalar operand you use!</p>

</li>
<li><p><code>$string = $vector-&gt;to_Enum();</code></p>

<p>Converts the given bit vector or set into an enumeration of single indices and ranges of indices (&quot;.newsrc&quot; style), representing the bits that are set (&quot;<code>1</code>&quot;) in the bit vector.</p>

<p>Example:</p>

<pre><code>  $vector = Bit::Vector-&gt;new(20);
  $vector-&gt;Bit_On(2);
  $vector-&gt;Bit_On(3);
  $vector-&gt;Bit_On(11);
  $vector-&gt;Interval_Fill(5,7);
  $vector-&gt;Interval_Fill(13,19);
  print &quot;&#39;&quot;, $vector-&gt;to_Enum(), &quot;&#39;\n&quot;;</code></pre>

<p>which prints</p>

<pre><code>  &#39;2,3,5-7,11,13-19&#39;</code></pre>

<p>If the given bit vector is empty, the resulting string will also be empty.</p>

<p>Note, by the way, that the above example can also be written a little handier, perhaps, as follows:</p>

<pre><code>  Bit::Vector-&gt;Configuration(&quot;out=enum&quot;);
  $vector = Bit::Vector-&gt;new(20);
  $vector-&gt;Index_List_Store(2,3,5,6,7,11,13,14,15,16,17,18,19);
  print &quot;&#39;$vector&#39;\n&quot;;</code></pre>

</li>
<li><p><code>$vector-&gt;from_Enum($string);</code></p>

<p>This method first empties the given bit vector and then tries to set the bits and ranges of bits specified in the given string.</p>

<p>The string &quot;<code>$string</code>&quot; must only contain unsigned integers or ranges of integers (two unsigned integers separated by a dash &quot;-&quot;), separated by commas (&quot;,&quot;).</p>

<p>All other characters are disallowed (including white space!) and will lead to a fatal &quot;input string syntax error&quot;.</p>

<p>In each range, the first integer (the lower limit of the range) must always be less than or equal to the second integer (the upper limit), or a fatal &quot;minimum &gt; maximum index&quot; error occurs.</p>

<p>All integers must lie in the permitted range for the given bit vector, i.e., they must lie between &quot;<code>0</code>&quot; and &quot;<code>$vector-&gt;Size()-1</code>&quot;.</p>

<p>If this condition is not met, a fatal &quot;index out of range&quot; error occurs.</p>

<p>If possible program abortion is unwanted or intolerable, use &quot;<code>eval</code>&quot;, like this:</p>

<pre><code>  eval { $vector-&gt;from_Enum(&quot;2,3,5-7,11,13-19&quot;); };
  if ($@)
  {
      # an error occurred
  }</code></pre>

<p>There are four possible error messages:</p>

<pre><code>  if ($@ =~ /item is not a string/)

  if ($@ =~ /input string syntax error/)

  if ($@ =~ /index out of range/)

  if ($@ =~ /minimum &gt; maximum index/)</code></pre>

<p>Note that the order of the indices and ranges is irrelevant, i.e.,</p>

<pre><code>  eval { $vector-&gt;from_Enum(&quot;11,5-7,3,13-19,2&quot;); };</code></pre>

<p>results in the same vector as in the example above.</p>

<p>Ranges and indices may also overlap.</p>

<p>This is because each (single) index in the string is passed to the method &quot;<code>Bit_On()</code>&quot;, internally, and each range to the method &quot;<code>Interval_Fill()</code>&quot;.</p>

<p>This means that the resulting bit vector is just the union of all the indices and ranges specified in the given string.</p>

</li>
<li><p><code>$vector-&gt;Bit_Off($index);</code></p>

<p>Clears the bit with index &quot;<code>$index</code>&quot; in the given vector.</p>

</li>
<li><p><code>$vector-&gt;Bit_On($index);</code></p>

<p>Sets the bit with index &quot;<code>$index</code>&quot; in the given vector.</p>

</li>
<li><p><code>$vector-&gt;bit_flip($index)</code></p>

<p>Flips (i.e., complements) the bit with index &quot;<code>$index</code>&quot; in the given vector.</p>

<p>Moreover, this method returns the <b>NEW</b> state of the bit in question, i.e., it returns &quot;<code>0</code>&quot; if the bit is cleared or &quot;<code>1</code>&quot; if the bit is set (<b>AFTER</b> flipping it).</p>

</li>
<li><p><code>if ($vector-&gt;bit_test($index))</code></p>

<p><code>if ($vector-&gt;contains($index))</code></p>

<p>Returns the current state of the bit with index &quot;<code>$index</code>&quot; in the given vector, i.e., returns &quot;<code>0</code>&quot; if it is cleared (in the &quot;off&quot; state) or &quot;<code>1</code>&quot; if it is set (in the &quot;on&quot; state).</p>

</li>
<li><p><code>$vector-&gt;Bit_Copy($index,$bit);</code></p>

<p>Sets the bit with index &quot;<code>$index</code>&quot; in the given vector either to &quot;<code>0</code>&quot; or &quot;<code>1</code>&quot; depending on the boolean value &quot;<code>$bit</code>&quot;.</p>

</li>
<li><p><code>$vector-&gt;LSB($bit);</code></p>

<p>Allows you to set the least significant bit in the given bit vector to the value given by the boolean parameter &quot;<code>$bit</code>&quot;.</p>

<p>This is a (faster) shortcut for &quot;<code>$vector-&gt;Bit_Copy(0,$bit);</code>&quot;.</p>

</li>
<li><p><code>$vector-&gt;MSB($bit);</code></p>

<p>Allows you to set the most significant bit in the given bit vector to the value given by the boolean parameter &quot;<code>$bit</code>&quot;.</p>

<p>This is a (faster) shortcut for &quot;<code>$vector-&gt;Bit_Copy($vector-&gt;Size()-1,$bit);</code>&quot;.</p>

</li>
<li><p><code>$bit = $vector-&gt;lsb();</code></p>

<p>Returns the least significant bit of the given bit vector.</p>

<p>This is a (faster) shortcut for &quot;<code>$bit = $vector-&gt;bit_test(0);</code>&quot;.</p>

</li>
<li><p><code>$bit = $vector-&gt;msb();</code></p>

<p>Returns the most significant bit of the given bit vector.</p>

<p>This is a (faster) shortcut for &quot;<code>$bit = $vector-&gt;bit_test($vector-&gt;Size()-1);</code>&quot;.</p>

</li>
<li><p><code>$carry_out = $vector-&gt;rotate_left();</code></p>

<pre><code>  carry             MSB           vector:           LSB
   out:
  +---+            +---+---+---+---     ---+---+---+---+
  |   |  &lt;---+---  |   |   |   |    ...    |   |   |   |  &lt;---+
  +---+      |     +---+---+---+---     ---+---+---+---+      |
             |                                                |
             +------------------------------------------------+</code></pre>

<p>The least significant bit (LSB) is the bit with index &quot;<code>0</code>&quot;, the most significant bit (MSB) is the bit with index &quot;<code>$vector-&gt;Size()-1</code>&quot;.</p>

</li>
<li><p><code>$carry_out = $vector-&gt;rotate_right();</code></p>

<pre><code>          MSB           vector:           LSB            carry
                                                          out:
         +---+---+---+---     ---+---+---+---+           +---+
  +---&gt;  |   |   |   |    ...    |   |   |   |  ---+---&gt; |   |
  |      +---+---+---+---     ---+---+---+---+     |     +---+
  |                                                |
  +------------------------------------------------+</code></pre>

<p>The least significant bit (LSB) is the bit with index &quot;<code>0</code>&quot;, the most significant bit (MSB) is the bit with index &quot;<code>$vector-&gt;Size()-1</code>&quot;.</p>

</li>
<li><p><code>$carry_out = $vector-&gt;shift_left($carry_in);</code></p>

<pre><code>  carry         MSB           vector:           LSB         carry
   out:                                                      in:
  +---+        +---+---+---+---     ---+---+---+---+        +---+
  |   |  &lt;---  |   |   |   |    ...    |   |   |   |  &lt;---  |   |
  +---+        +---+---+---+---     ---+---+---+---+        +---+</code></pre>

<p>The least significant bit (LSB) is the bit with index &quot;<code>0</code>&quot;, the most significant bit (MSB) is the bit with index &quot;<code>$vector-&gt;Size()-1</code>&quot;.</p>

</li>
<li><p><code>$carry_out = $vector-&gt;shift_right($carry_in);</code></p>

<pre><code>  carry         MSB           vector:           LSB         carry
   in:                                                       out:
  +---+        +---+---+---+---     ---+---+---+---+        +---+
  |   |  ---&gt;  |   |   |   |    ...    |   |   |   |  ---&gt;  |   |
  +---+        +---+---+---+---     ---+---+---+---+        +---+</code></pre>

<p>The least significant bit (LSB) is the bit with index &quot;<code>0</code>&quot;, the most significant bit (MSB) is the bit with index &quot;<code>$vector-&gt;Size()-1</code>&quot;.</p>

</li>
<li><p><code>$vector-&gt;Move_Left($bits);</code></p>

<p>Shifts the given bit vector left by &quot;<code>$bits</code>&quot; bits, i.e., inserts &quot;<code>$bits</code>&quot; new bits at the lower end (least significant bit) of the bit vector, moving all other bits up by &quot;<code>$bits</code>&quot; places, thereby losing the &quot;<code>$bits</code>&quot; most significant bits.</p>

<p>The inserted new bits are all cleared (set to the &quot;off&quot; state).</p>

<p>This method does nothing if &quot;<code>$bits</code>&quot; is equal to zero.</p>

<p>Beware that the whole bit vector is cleared <b>WITHOUT WARNING</b> if &quot;<code>$bits</code>&quot; is greater than or equal to the size of the given bit vector!</p>

<p>In fact this method is equivalent to</p>

<pre><code>  for ( $i = 0; $i &lt; $bits; $i++ ) { $vector-&gt;shift_left(0); }</code></pre>

<p>except that it is much more efficient (for &quot;<code>$bits</code>&quot; greater than or equal to the number of bits in a machine word on your system) than this straightforward approach.</p>

</li>
<li><p><code>$vector-&gt;Move_Right($bits);</code></p>

<p>Shifts the given bit vector right by &quot;<code>$bits</code>&quot; bits, i.e., deletes the &quot;<code>$bits</code>&quot; least significant bits of the bit vector, moving all other bits down by &quot;<code>$bits</code>&quot; places, thereby creating &quot;<code>$bits</code>&quot; new bits at the upper end (most significant bit) of the bit vector.</p>

<p>These new bits are all cleared (set to the &quot;off&quot; state).</p>

<p>This method does nothing if &quot;<code>$bits</code>&quot; is equal to zero.</p>

<p>Beware that the whole bit vector is cleared <b>WITHOUT WARNING</b> if &quot;<code>$bits</code>&quot; is greater than or equal to the size of the given bit vector!</p>

<p>In fact this method is equivalent to</p>

<pre><code>  for ( $i = 0; $i &lt; $bits; $i++ ) { $vector-&gt;shift_right(0); }</code></pre>

<p>except that it is much more efficient (for &quot;<code>$bits</code>&quot; greater than or equal to the number of bits in a machine word on your system) than this straightforward approach.</p>

</li>
<li><p><code>$vector-&gt;Insert($offset,$bits);</code></p>

<p>This method inserts &quot;<code>$bits</code>&quot; fresh new bits at position &quot;<code>$offset</code>&quot; in the given bit vector.</p>

<p>The &quot;<code>$bits</code>&quot; most significant bits are lost, and all bits starting with bit number &quot;<code>$offset</code>&quot; up to and including bit number &quot;<code>$vector-&gt;Size()-$bits-1</code>&quot; are moved up by &quot;<code>$bits</code>&quot; places.</p>

<p>The now vacant &quot;<code>$bits</code>&quot; bits starting at bit number &quot;<code>$offset</code>&quot; (up to and including bit number &quot;<code>$offset+$bits-1</code>&quot;) are then set to zero (cleared).</p>

<p>Note that this method does <b>NOT</b> increase the size of the given bit vector, i.e., the bit vector is <b>NOT</b> extended at its upper end to &quot;rescue&quot; the &quot;<code>$bits</code>&quot; uppermost (most significant) bits - instead, these bits are lost forever.</p>

<p>If you don&#39;t want this to happen, you have to increase the size of the given bit vector <b>EXPLICITLY</b> and <b>BEFORE</b> you perform the &quot;Insert&quot; operation, with a statement such as the following:</p>

<pre><code>  $vector-&gt;Resize($vector-&gt;Size() + $bits);</code></pre>

<p>Or use the method &quot;<code>Interval_Substitute()</code>&quot; instead of &quot;<code>Insert()</code>&quot;, which performs automatic growing and shrinking of its target bit vector.</p>

<p>Note also that &quot;<code>$offset</code>&quot; must lie in the permitted range between &quot;<code>0</code>&quot; and &quot;<code>$vector-&gt;Size()-1</code>&quot;, or a fatal &quot;offset out of range&quot; error will occur.</p>

<p>If the term &quot;<code>$offset + $bits</code>&quot; exceeds &quot;<code>$vector-&gt;Size()-1</code>&quot;, all the bits starting with bit number &quot;<code>$offset</code>&quot; up to bit number &quot;<code>$vector-&gt;Size()-1</code>&quot; are simply cleared.</p>

</li>
<li><p><code>$vector-&gt;Delete($offset,$bits);</code></p>

<p>This method deletes, i.e., removes the bits starting at position &quot;<code>$offset</code>&quot; up to and including bit number &quot;<code>$offset+$bits-1</code>&quot; from the given bit vector.</p>

<p>The remaining uppermost bits (starting at position &quot;<code>$offset+$bits</code>&quot; up to and including bit number &quot;<code>$vector-&gt;Size()-1</code>&quot;) are moved down by &quot;<code>$bits</code>&quot; places.</p>

<p>The now vacant uppermost (most significant) &quot;<code>$bits</code>&quot; bits are then set to zero (cleared).</p>

<p>Note that this method does <b>NOT</b> decrease the size of the given bit vector, i.e., the bit vector is <b>NOT</b> clipped at its upper end to &quot;get rid of&quot; the vacant &quot;<code>$bits</code>&quot; uppermost bits.</p>

<p>If you don&#39;t want this, i.e., if you want the bit vector to shrink accordingly, you have to do so <b>EXPLICITLY</b> and <b>AFTER</b> the &quot;Delete&quot; operation, with a couple of statements such as these:</p>

<pre><code>  $size = $vector-&gt;Size();
  if ($bits &gt; $size) { $bits = $size; }
  $vector-&gt;Resize($size - $bits);</code></pre>

<p>Or use the method &quot;<code>Interval_Substitute()</code>&quot; instead of &quot;<code>Delete()</code>&quot;, which performs automatic growing and shrinking of its target bit vector.</p>

<p>Note also that &quot;<code>$offset</code>&quot; must lie in the permitted range between &quot;<code>0</code>&quot; and &quot;<code>$vector-&gt;Size()-1</code>&quot;, or a fatal &quot;offset out of range&quot; error will occur.</p>

<p>If the term &quot;<code>$offset + $bits</code>&quot; exceeds &quot;<code>$vector-&gt;Size()-1</code>&quot;, all the bits starting with bit number &quot;<code>$offset</code>&quot; up to bit number &quot;<code>$vector-&gt;Size()-1</code>&quot; are simply cleared.</p>

</li>
<li><p><code>$carry = $vector-&gt;increment();</code></p>

<p>This method increments the given bit vector.</p>

<p>Note that this method regards bit vectors as being unsigned, i.e., the largest possible positive number is directly followed by the smallest possible (or greatest possible, speaking in absolute terms) negative number:</p>

<pre><code>  before:  2 ^ (b-1) - 1    (= &quot;0111...1111&quot;)
  after:   2 ^ (b-1)        (= &quot;1000...0000&quot;)</code></pre>

<p>where &quot;<code>b</code>&quot; is the number of bits of the given bit vector.</p>

<p>The method returns &quot;false&quot; (&quot;<code>0</code>&quot;) in all cases except when a carry over occurs (in which case it returns &quot;true&quot;, i.e., &quot;<code>1</code>&quot;), which happens when the number &quot;1111...1111&quot; is incremented, which gives &quot;0000...0000&quot; plus a carry over to the next higher (binary) digit.</p>

<p>This can be used for the terminating condition of a &quot;while&quot; loop, for instance, in order to cycle through all possible values the bit vector can assume.</p>

</li>
<li><p><code>$carry = $vector-&gt;decrement();</code></p>

<p>This method decrements the given bit vector.</p>

<p>Note that this method regards bit vectors as being unsigned, i.e., the smallest possible (or greatest possible, speaking in absolute terms) negative number is directly followed by the largest possible positive number:</p>

<pre><code>  before:  2 ^ (b-1)        (= &quot;1000...0000&quot;)
  after:   2 ^ (b-1) - 1    (= &quot;0111...1111&quot;)</code></pre>

<p>where &quot;<code>b</code>&quot; is the number of bits of the given bit vector.</p>

<p>The method returns &quot;false&quot; (&quot;<code>0</code>&quot;) in all cases except when a carry over occurs (in which case it returns &quot;true&quot;, i.e., &quot;<code>1</code>&quot;), which happens when the number &quot;0000...0000&quot; is decremented, which gives &quot;1111...1111&quot; minus a carry over to the next higher (binary) digit.</p>

<p>This can be used for the terminating condition of a &quot;while&quot; loop, for instance, in order to cycle through all possible values the bit vector can assume.</p>

</li>
<li><p><code>$overflow = $vec2-&gt;inc($vec1);</code></p>

<p>This method copies the contents of bit vector &quot;<code>$vec1</code>&quot; to bit vector &quot;<code>$vec2</code>&quot; and increments the copy (not the original).</p>

<p>If by incrementing the number its sign becomes invalid, the return value (&quot;overflow&quot; flag) will be true (&quot;<code>1</code>&quot;), or false (&quot;<code>0</code>&quot;) if not. (See the description of the method &quot;add()&quot; below for a more in-depth explanation of what &quot;overflow&quot; means).</p>

<p>Note that in-place operation is also possible, i.e., &quot;<code>$vec1</code>&quot; and &quot;<code>$vec2</code>&quot; may be identical.</p>

</li>
<li><p><code>$overflow = $vec2-&gt;dec($vec1);</code></p>

<p>This method copies the contents of bit vector &quot;<code>$vec1</code>&quot; to bit vector &quot;<code>$vec2</code>&quot; and decrements the copy (not the original).</p>

<p>If by decrementing the number its sign becomes invalid, the return value (&quot;overflow&quot; flag) will be true (&quot;<code>1</code>&quot;), or false (&quot;<code>0</code>&quot;) if not. (See the description of the method &quot;subtract()&quot; below for a more in-depth explanation of what &quot;overflow&quot; means).</p>

<p>Note that in-place operation is also possible, i.e., &quot;<code>$vec1</code>&quot; and &quot;<code>$vec2</code>&quot; may be identical.</p>

</li>
<li><p><code>$carry = $vec3-&gt;add($vec1,$vec2,$carry);</code></p>

<p><code>($carry,$overflow) = $vec3-&gt;add($vec1,$vec2,$carry);</code></p>

<p>This method adds the two numbers contained in bit vector &quot;<code>$vec1</code>&quot; and &quot;<code>$vec2</code>&quot; with carry &quot;<code>$carry</code>&quot; and stores the result in bit vector &quot;<code>$vec3</code>&quot;.</p>

<p>I.e., $vec3 = $vec1 + $vec2 + $carry</p>

<p>Note that the &quot;<code>$carry</code>&quot; parameter is a boolean value, i.e., only its least significant bit is taken into account. (Think of it as though &quot;<code>$carry &amp;= 1;</code>&quot; was always executed internally.)</p>

<p>In scalar context, the method returns a boolean value which indicates if a carry over (to the next higher bit position) has occured. In list context, the method returns the carry and the overflow flag (in this order).</p>

<p>The overflow flag is true (&quot;<code>1</code>&quot;) if the sign (i.e., the most significant bit) of the result is wrong. This can happen when adding two very large positive numbers or when adding two (by their absolute value) very large negative numbers. See also further below.</p>

<p>The carry in- and output is needed mainly for cascading, i.e., to add numbers that are fragmented into several pieces.</p>

<p>Example:</p>

<pre><code>  # initialize

  for ( $i = 0; $i &lt; $n; $i++ )
  {
      $a[$i] = Bit::Vector-&gt;new($bits);
      $b[$i] = Bit::Vector-&gt;new($bits);
      $c[$i] = Bit::Vector-&gt;new($bits);
  }

  # fill @a and @b

  # $a[  0 ] is low order part,
  # $a[$n-1] is high order part,
  # and same for @b

  # add

  $carry = 0;
  for ( $i = 0; $i &lt; $n; $i++ )
  {
      $carry = $c[$i]-&gt;add($a[$i],$b[$i],$carry);
  }</code></pre>

<p>Note that it makes no difference to this method whether the numbers in &quot;<code>$vec1</code>&quot; and &quot;<code>$vec2</code>&quot; are unsigned or signed (i.e., in two&#39;s complement binary representation).</p>

<p>Note however that the return value (carry flag) is not meaningful when the numbers are <b>SIGNED</b>.</p>

<p>Moreover, when the numbers are signed, a special type of error can occur which is commonly called an &quot;overflow error&quot;.</p>

<p>An overflow error occurs when the sign of the result (its most significant bit) is flipped (i.e., falsified) by a carry over from the next-lower bit position (&quot;MSB-1&quot;).</p>

<p>In fact matters are a bit more complicated than that: the overflow flag is set to &quot;true&quot; whenever there is a carry over from bit position MSB-1 to the most significant bit (MSB) but no carry over from the MSB to the output carry flag, or vice-versa, i.e., when there is no carry over from bit position MSB-1 to the most significant bit (MSB) but a carry over to the output carry flag.</p>

<p>Thus the overflow flag is the result of an exclusive-or operation between incoming and outgoing carry over at the most significant bit position.</p>

</li>
<li><p><code>$carry = $vec3-&gt;subtract($vec1,$vec2,$carry);</code></p>

<p><code>($carry,$overflow) = $vec3-&gt;subtract($vec1,$vec2,$carry);</code></p>

<p>This method subtracts the two numbers contained in bit vector &quot;<code>$vec1</code>&quot; and &quot;<code>$vec2</code>&quot; with carry &quot;<code>$carry</code>&quot; and stores the result in bit vector &quot;<code>$vec3</code>&quot;.</p>

<p>I.e., $vec3 = $vec1 - $vec2 - $carry</p>

<p>Note that the &quot;<code>$carry</code>&quot; parameter is a boolean value, i.e., only its least significant bit is taken into account. (Think of it as though &quot;<code>$carry &amp;= 1;</code>&quot; was always executed internally.)</p>

<p>In scalar context, the method returns a boolean value which indicates if a carry over (to the next higher bit position) has occured. In list context, the method returns the carry and the overflow flag (in this order).</p>

<p>The overflow flag is true (&quot;<code>1</code>&quot;) if the sign (i.e., the most significant bit) of the result is wrong. This can happen when subtracting a very large negative number from a very large positive number or vice-versa. See also further below.</p>

<p>The carry in- and output is needed mainly for cascading, i.e., to subtract numbers that are fragmented into several pieces.</p>

<p>Example:</p>

<pre><code>  # initialize

  for ( $i = 0; $i &lt; $n; $i++ )
  {
      $a[$i] = Bit::Vector-&gt;new($bits);
      $b[$i] = Bit::Vector-&gt;new($bits);
      $c[$i] = Bit::Vector-&gt;new($bits);
  }

  # fill @a and @b

  # $a[  0 ] is low order part,
  # $a[$n-1] is high order part,
  # and same for @b

  # subtract

  $carry = 0;
  for ( $i = 0; $i &lt; $n; $i++ )
  {
      $carry = $c[$i]-&gt;subtract($a[$i],$b[$i],$carry);
  }</code></pre>

<p>Note that it makes no difference to this method whether the numbers in &quot;<code>$vec1</code>&quot; and &quot;<code>$vec2</code>&quot; are unsigned or signed (i.e., in two&#39;s complement binary representation).</p>

<p>Note however that the return value (carry flag) is not meaningful when the numbers are <b>SIGNED</b>.</p>

<p>Moreover, when the numbers are signed, a special type of error can occur which is commonly called an &quot;overflow error&quot;.</p>

<p>An overflow error occurs when the sign of the result (its most significant bit) is flipped (i.e., falsified) by a carry over from the next-lower bit position (&quot;MSB-1&quot;).</p>

<p>In fact matters are a bit more complicated than that: the overflow flag is set to &quot;true&quot; whenever there is a carry over from bit position MSB-1 to the most significant bit (MSB) but no carry over from the MSB to the output carry flag, or vice-versa, i.e., when there is no carry over from bit position MSB-1 to the most significant bit (MSB) but a carry over to the output carry flag.</p>

<p>Thus the overflow flag is the result of an exclusive-or operation between incoming and outgoing carry over at the most significant bit position.</p>

</li>
<li><p><code>$vec2-&gt;Neg($vec1);</code></p>

<p><code>$vec2-&gt;Negate($vec1);</code></p>

<p>This method calculates the two&#39;s complement of the number in bit vector &quot;<code>$vec1</code>&quot; and stores the result in bit vector &quot;<code>$vec2</code>&quot;.</p>

<p>Calculating the two&#39;s complement of a given number in binary representation consists of inverting all bits and incrementing the result by one.</p>

<p>This is the same as changing the sign of the given number from &quot;<code>+</code>&quot; to &quot;<code>-</code>&quot; or vice-versa. In other words, applying this method twice on a given number yields the original number again.</p>

<p>Note that in-place processing is also possible, i.e., &quot;<code>$vec1</code>&quot; and &quot;<code>$vec2</code>&quot; may be identical.</p>

<p>Most importantly, beware that this method produces a counter-intuitive result if the number contained in bit vector &quot;<code>$vec1</code>&quot; is <code>2 ^ (n-1)</code> (i.e., &quot;1000...0000&quot;), where &quot;<code>n</code>&quot; is the number of bits the given bit vector contains: The negated value of this number is the number itself!</p>

</li>
<li><p><code>$vec2-&gt;Abs($vec1);</code></p>

<p><code>$vec2-&gt;Absolute($vec1);</code></p>

<p>Depending on the sign (i.e., the most significant bit) of the number in bit vector &quot;<code>$vec1</code>&quot;, the contents of bit vector &quot;<code>$vec1</code>&quot; are copied to bit vector &quot;<code>$vec2</code>&quot; either with the method &quot;<code>Copy()</code>&quot; (if the number in bit vector &quot;<code>$vec1</code>&quot; is positive), or with &quot;<code>Negate()</code>&quot; (if the number in bit vector &quot;<code>$vec1</code>&quot; is negative).</p>

<p>In other words, this method calculates the absolute value of the number in bit vector &quot;<code>$vec1</code>&quot; and stores the result in bit vector &quot;<code>$vec2</code>&quot;.</p>

<p>Note that in-place processing is also possible, i.e., &quot;<code>$vec1</code>&quot; and &quot;<code>$vec2</code>&quot; may be identical.</p>

<p>Most importantly, beware that this method produces a counter-intuitive result if the number contained in bit vector &quot;<code>$vec1</code>&quot; is <code>2 ^ (n-1)</code> (i.e., &quot;1000...0000&quot;), where &quot;<code>n</code>&quot; is the number of bits the given bit vector contains: The absolute value of this number is the number itself, even though this number is still negative by definition (the most significant bit is still set)!</p>

</li>
<li><p><code>$sign = $vector-&gt;Sign();</code></p>

<p>This method returns &quot;<code>0</code>&quot; if all bits in the given bit vector are cleared, i.e., if the given bit vector contains the number &quot;<code>0</code>&quot;, or if the given bit vector has a length of zero (contains no bits at all).</p>

<p>If not all bits are cleared, this method returns &quot;<code>-1</code>&quot; if the most significant bit is set (i.e., if the bit vector contains a negative number), or &quot;<code>1</code>&quot; otherwise (i.e., if the bit vector contains a positive number).</p>

</li>
<li><p><code>$vec3-&gt;Multiply($vec1,$vec2);</code></p>

<p>This method multiplies the two numbers contained in bit vector &quot;<code>$vec1</code>&quot; and &quot;<code>$vec2</code>&quot; and stores the result in bit vector &quot;<code>$vec3</code>&quot;.</p>

<p>Note that this method regards its arguments as <b>SIGNED</b>.</p>

<p>If you want to make sure that a large number can never be treated as being negative by mistake, make your bit vectors at least one bit longer than the largest number you wish to represent, right from the start, or proceed as follows:</p>

<pre><code>    $msb1 = $vec1-&gt;msb();
    $msb2 = $vec2-&gt;msb();
    $vec1-&gt;Resize($vec1-&gt;Size()+1);
    $vec2-&gt;Resize($vec2-&gt;Size()+1);
    $vec3-&gt;Resize($vec3-&gt;Size()+1);
    $vec1-&gt;MSB($msb1);
    $vec2-&gt;MSB($msb2);
    $vec3-&gt;Multiply($vec1,$vec2);</code></pre>

<p>Note also that all three bit vector arguments must in principle obey the rule of matching sizes, but that the bit vector &quot;<code>$vec3</code>&quot; may be larger than the two factors &quot;<code>$vec1</code>&quot; and &quot;<code>$vec2</code>&quot;.</p>

<p>In fact multiplying two binary numbers with &quot;<code>n</code>&quot; bits may yield a result which is at most &quot;<code>2n</code>&quot; bits long.</p>

<p>Therefore, it is usually a good idea to let bit vector &quot;<code>$vec3</code>&quot; have twice the size of bit vector &quot;<code>$vec1</code>&quot; and &quot;<code>$vec2</code>&quot;, unless you are absolutely sure that the result will fit into a bit vector of the same size as the two factors.</p>

<p>If you are wrong, a fatal &quot;numeric overflow error&quot; will occur.</p>

<p>Finally, note that in-place processing is possible, i.e., &quot;<code>$vec3</code>&quot; may be identical with &quot;<code>$vec1</code>&quot; or &quot;<code>$vec2</code>&quot;, or both.</p>

</li>
<li><p><code>$quot-&gt;Divide($vec1,$vec2,$rest);</code></p>

<p>This method divides the two numbers contained in bit vector &quot;<code>$vec1</code>&quot; and &quot;<code>$vec2</code>&quot; and stores the quotient in bit vector &quot;<code>$quot</code>&quot; and the remainder in bit vector &quot;<code>$rest</code>&quot;.</p>

<p>I.e., $quot = $vec1 / $vec2; # div $rest = $vec1 % $vec2; # mod</p>

<p>Therefore, &quot;<code>$quot</code>&quot; and &quot;<code>$rest</code>&quot; must be two <b>DISTINCT</b> bit vectors, or a fatal &quot;result vector(s) must be distinct&quot; error will occur.</p>

<p>Note also that a fatal &quot;division by zero error&quot; will occur if &quot;<code>$vec2</code>&quot; is equal to zero.</p>

<p>Note further that this method regards its arguments as <b>SIGNED</b>.</p>

<p>If you want to make sure that a large number can never be treated as being negative by mistake, make your bit vectors at least one bit longer than the largest number you wish to represent, right from the start, or proceed as follows:</p>

<pre><code>    $msb1 = $vec1-&gt;msb();
    $msb2 = $vec2-&gt;msb();
    $vec1-&gt;Resize($vec1-&gt;Size()+1);
    $vec2-&gt;Resize($vec2-&gt;Size()+1);
    $quot-&gt;Resize($quot-&gt;Size()+1);
    $rest-&gt;Resize($rest-&gt;Size()+1);
    $vec1-&gt;MSB($msb1);
    $vec2-&gt;MSB($msb2);
    $quot-&gt;Divide($vec1,$vec2,$rest);</code></pre>

<p>Finally, note that in-place processing is possible, i.e., &quot;<code>$quot</code>&quot; may be identical with &quot;<code>$vec1</code>&quot; or &quot;<code>$vec2</code>&quot; or both, and &quot;<code>$rest</code>&quot; may also be identical with &quot;<code>$vec1</code>&quot; or &quot;<code>$vec2</code>&quot; or both, as long as &quot;<code>$quot</code>&quot; and &quot;<code>$rest</code>&quot; are distinct. (!)</p>

</li>
<li><p><code>$vecgcd-&gt;GCD($veca,$vecb);</code></p>

<p>This method calculates the &quot;Greatest Common Divisor&quot; of the two numbers contained in bit vector &quot;<code>$veca</code>&quot; and &quot;<code>$vecb</code>&quot; and stores the result in bit vector &quot;<code>$vecgcd</code>&quot;.</p>

<p>The method uses Euklid&#39;s algorithm internally:</p>

<pre><code>    int GCD(int a, int b)
    {
        int t;

        while (b != 0)
        {
            t = a % b; /* = remainder of (a div b) */
            a = b;
            b = t;
        }
        return(a);
    }</code></pre>

<p>Note that <code>GCD(z,0) == GCD(0,z) == z</code>.</p>

</li>
<li><p><code>$vecgcd-&gt;GCD($vecx,$vecy,$veca,$vecb);</code></p>

<p>This variant of the &quot;GCD&quot; method calculates the &quot;Greatest Common Divisor&quot; of the two numbers contained in bit vector &quot;<code>$veca</code>&quot; and &quot;<code>$vecb</code>&quot; and stores the result in bit vector &quot;<code>$vecgcd</code>&quot;.</p>

<p>Moreover, it determines the two factors which are necessary in order to represent the greatest common divisor as a linear combination of its two arguments, i.e., the two factors <code>&quot;x&quot;</code> and <code>&quot;y&quot;</code> so that <code>GCD(a,b) == x * a + y * b</code>, and stores them in bit vector &quot;<code>$vecx</code>&quot; and &quot;<code>$vecy</code>&quot;, respectively.</p>

<p>For example:</p>

<pre><code>  a = 2322
  b =  654

  GCD( 2322, 654 ) == 6

  x =  20
  y = -71

  20 * 2322 - 71 * 654 == 6</code></pre>

<p>Please see http://www.cut-the-knot.org/blue/extension.shtml for an explanation of how this extension of Euklid&#39;s algorithm works.</p>

</li>
<li><p><code>$vec3-&gt;Power($vec1,$vec2);</code></p>

<p>This method calculates the exponentiation of base &quot;<code>$vec1</code>&quot; elevated to the &quot;<code>$vec2</code>&quot; power, i.e., &quot;<code>$vec1 ** $vec2</code>&quot;, and stores the result in bit vector &quot;<code>$vec3</code>&quot;.</p>

<p>The method uses an efficient divide-and-conquer algorithm:</p>

<p>Suppose the exponent is (decimal) 13, for example. The binary representation of this exponent is &quot;1101&quot;.</p>

<p>This means we want to calculate</p>

<pre><code>  $vec1 * $vec1 * $vec1 * $vec1 * $vec1 * $vec1 * $vec1 * $vec1 *
  $vec1 * $vec1 * $vec1 * $vec1 *
  $vec1</code></pre>

<p>That is, &quot;<code>$vec1</code>&quot; multiplied with itself 13 times. The grouping into lines above is no coincidence. The first line comprises 8 factors, the second contains 4, and the last line just one. This just happens to be the binary representation of 13. <code>;-)</code></p>

<p>We then calculate a series of squares (of squares of squares...) of the base, i.e.,</p>

<pre><code>  $power[0] = $vec1;
  $power[1] = $vec1 * $vec1;
  $power[2] = $power[1] * $power[1];
  $power[3] = $power[2] * $power[2];
  etc.</code></pre>

<p>To calculate the power of our example, we simply initialize our result with 1 and consecutively multiply it with the items of the series of powers we just calculated, if the corresponding bit of the binary representation of the exponent is set:</p>

<pre><code>  $result = 1;
  $result *= $power[0] if ($vec2 &amp; 1);
  $result *= $power[1] if ($vec2 &amp; 2);
  $result *= $power[2] if ($vec2 &amp; 4);
  $result *= $power[3] if ($vec2 &amp; 8);
  etc.</code></pre>

<p>The bit vector &quot;<code>$vec3</code>&quot; must be of the same size as the base &quot;<code>$vec1</code>&quot; or greater. &quot;<code>$vec3</code>&quot; and &quot;<code>$vec1</code>&quot; may be the same vector (i.e., in-place calculation as in &quot;<code>$vec1 **= $vec2;</code>&quot; is possible), but &quot;<code>$vec3</code>&quot; and &quot;<code>$vec2</code>&quot; must be distinct. Finally, the exponent &quot;<code>$vec2</code>&quot; must be positive. A fatal error occurs if any of these conditions is not met.</p>

</li>
<li><p><code>$vector-&gt;Block_Store($buffer);</code></p>

<p>This method allows you to load the contents of a given bit vector in one go.</p>

<p>This is useful when you store the contents of a bit vector in a file, for instance (using method &quot;<code>Block_Read()</code>&quot;), and when you want to restore the previously saved bit vector.</p>

<p>For this, &quot;<code>$buffer</code>&quot; <b>MUST</b> be a string (<b>NO</b> automatic conversion from numeric to string is provided here as would normally in Perl!) containing the bit vector in &quot;low order byte first&quot; order.</p>

<p>If the given string is shorter than what is needed to completely fill the given bit vector, the remaining (most significant) bytes of the bit vector are filled with zeros, i.e., the previous contents of the bit vector are always erased completely.</p>

<p>If the given string is longer than what is needed to completely fill the given bit vector, the superfluous bytes are simply ignored.</p>

<p>See <a href="functions/CORE.html#sysread">&quot;sysread&quot; in perlfunc</a> for how to read in the contents of &quot;<code>$buffer</code>&quot; from a file prior to passing it to this method.</p>

</li>
<li><p><code>$buffer = $vector-&gt;Block_Read();</code></p>

<p>This method allows you to export the contents of a given bit vector in one block.</p>

<p>This is useful when you want to save the contents of a bit vector for later, for instance in a file.</p>

<p>The advantage of this method is that it allows you to do so in the compactest possible format, in binary.</p>

<p>The method returns a Perl string which contains an exact copy of the contents of the given bit vector in &quot;low order byte first&quot; order.</p>

<p>See <a href="functions/CORE.html#syswrite">&quot;syswrite&quot; in perlfunc</a> for how to write the data from this string to a file.</p>

</li>
<li><p><code>$size = $vector-&gt;Word_Size();</code></p>

<p>Each bit vector is internally organized as an array of machine words.</p>

<p>The methods whose names begin with &quot;Word_&quot; allow you to access this internal array of machine words.</p>

<p>Note that because the size of a machine word may vary from system to system, these methods are inherently <b>MACHINE-DEPENDENT</b>!</p>

<p>Therefore, <b>DO NOT USE</b> these methods unless you are absolutely certain that portability of your code is not an issue!</p>

<p>You have been warned!</p>

<p>To be machine-independent, use the methods whose names begin with &quot;<code>Chunk_</code>&quot; instead, with chunk sizes no greater than 32 bits.</p>

<p>The method &quot;<code>Word_Size()</code>&quot; returns the number of machine words that the internal array of words of the given bit vector contains.</p>

<p>This is similar in function to the term &quot;<code>scalar(@array)</code>&quot; for a Perl array.</p>

</li>
<li><p><code>$vector-&gt;Word_Store($offset,$word);</code></p>

<p>This method allows you to store a given value &quot;<code>$word</code>&quot; at a given position &quot;<code>$offset</code>&quot; in the internal array of words of the given bit vector.</p>

<p>Note that &quot;<code>$offset</code>&quot; must lie in the permitted range between &quot;<code>0</code>&quot; and &quot;<code>$vector-&gt;Word_Size()-1</code>&quot;, or a fatal &quot;offset out of range&quot; error will occur.</p>

<p>This method is similar in function to the expression &quot;<code>$array[$offset] = $word;</code>&quot; for a Perl array.</p>

</li>
<li><p><code>$word = $vector-&gt;Word_Read($offset);</code></p>

<p>This method allows you to access the value of a given machine word at position &quot;<code>$offset</code>&quot; in the internal array of words of the given bit vector.</p>

<p>Note that &quot;<code>$offset</code>&quot; must lie in the permitted range between &quot;<code>0</code>&quot; and &quot;<code>$vector-&gt;Word_Size()-1</code>&quot;, or a fatal &quot;offset out of range&quot; error will occur.</p>

<p>This method is similar in function to the expression &quot;<code>$word = $array[$offset];</code>&quot; for a Perl array.</p>

</li>
<li><p><code>$vector-&gt;Word_List_Store(@words);</code></p>

<p>This method allows you to store a list of values &quot;<code>@words</code>&quot; in the internal array of machine words of the given bit vector.</p>

<p>Thereby the <b>LEFTMOST</b> value in the list (&quot;<code>$words[0]</code>&quot;) is stored in the <b>LEAST</b> significant word of the internal array of words (the one with offset &quot;<code>0</code>&quot;), the next value from the list (&quot;<code>$words[1]</code>&quot;) is stored in the word with offset &quot;<code>1</code>&quot;, and so on, as intuitively expected.</p>

<p>If the list &quot;<code>@words</code>&quot; contains fewer elements than the internal array of words of the given bit vector contains machine words, the remaining (most significant) words are filled with zeros.</p>

<p>If the list &quot;<code>@words</code>&quot; contains more elements than the internal array of words of the given bit vector contains machine words, the superfluous values are simply ignored.</p>

<p>This method is comparable in function to the expression &quot;<code>@array = @words;</code>&quot; for a Perl array.</p>

</li>
<li><p><code>@words = $vector-&gt;Word_List_Read();</code></p>

<p>This method allows you to retrieve the internal array of machine words of the given bit vector all at once.</p>

<p>Thereby the <b>LEFTMOST</b> value in the returned list (&quot;<code>$words[0]</code>&quot;) is the <b>LEAST</b> significant word from the given bit vector, and the <b>RIGHTMOST</b> value in the returned list (&quot;<code>$words[$#words]</code>&quot;) is the <b>MOST</b> significant word of the given bit vector.</p>

<p>This method is similar in function to the expression &quot;<code>@words = @array;</code>&quot; for a Perl array.</p>

</li>
<li><p><code>$vector-&gt;Word_Insert($offset,$count);</code></p>

<p>This method inserts &quot;<code>$count</code>&quot; empty new machine words at position &quot;<code>$offset</code>&quot; in the internal array of words of the given bit vector.</p>

<p>The &quot;<code>$count</code>&quot; most significant words are lost, and all words starting with word number &quot;<code>$offset</code>&quot; up to and including word number &quot;<code>$vector-&gt;Word_Size()-$count-1</code>&quot; are moved up by &quot;<code>$count</code>&quot; places.</p>

<p>The now vacant &quot;<code>$count</code>&quot; words starting at word number &quot;<code>$offset</code>&quot; (up to and including word number &quot;<code>$offset+$count-1</code>&quot;) are then set to zero (cleared).</p>

<p>Note that this method does <b>NOT</b> increase the size of the given bit vector, i.e., the bit vector is <b>NOT</b> extended at its upper end to &quot;rescue&quot; the &quot;<code>$count</code>&quot; uppermost (most significant) words - instead, these words are lost forever.</p>

<p>If you don&#39;t want this to happen, you have to increase the size of the given bit vector <b>EXPLICITLY</b> and <b>BEFORE</b> you perform the &quot;Insert&quot; operation, with a statement such as the following:</p>

<pre><code>  $vector-&gt;Resize($vector-&gt;Size() + $count * Bit::Vector-&gt;Word_Bits());</code></pre>

<p>Note also that &quot;<code>$offset</code>&quot; must lie in the permitted range between &quot;<code>0</code>&quot; and &quot;<code>$vector-&gt;Word_Size()-1</code>&quot;, or a fatal &quot;offset out of range&quot; error will occur.</p>

<p>If the term &quot;<code>$offset + $count</code>&quot; exceeds &quot;<code>$vector-&gt;Word_Size()-1</code>&quot;, all the words starting with word number &quot;<code>$offset</code>&quot; up to word number &quot;<code>$vector-&gt;Word_Size()-1</code>&quot; are simply cleared.</p>

</li>
<li><p><code>$vector-&gt;Word_Delete($offset,$count);</code></p>

<p>This method deletes, i.e., removes the words starting at position &quot;<code>$offset</code>&quot; up to and including word number &quot;<code>$offset+$count-1</code>&quot; from the internal array of machine words of the given bit vector.</p>

<p>The remaining uppermost words (starting at position &quot;<code>$offset+$count</code>&quot; up to and including word number &quot;<code>$vector-&gt;Word_Size()-1</code>&quot;) are moved down by &quot;<code>$count</code>&quot; places.</p>

<p>The now vacant uppermost (most significant) &quot;<code>$count</code>&quot; words are then set to zero (cleared).</p>

<p>Note that this method does <b>NOT</b> decrease the size of the given bit vector, i.e., the bit vector is <b>NOT</b> clipped at its upper end to &quot;get rid of&quot; the vacant &quot;<code>$count</code>&quot; uppermost words.</p>

<p>If you don&#39;t want this, i.e., if you want the bit vector to shrink accordingly, you have to do so <b>EXPLICITLY</b> and <b>AFTER</b> the &quot;Delete&quot; operation, with a couple of statements such as these:</p>

<pre><code>  $bits = $vector-&gt;Size();
  $count *= Bit::Vector-&gt;Word_Bits();
  if ($count &gt; $bits) { $count = $bits; }
  $vector-&gt;Resize($bits - $count);</code></pre>

<p>Note also that &quot;<code>$offset</code>&quot; must lie in the permitted range between &quot;<code>0</code>&quot; and &quot;<code>$vector-&gt;Word_Size()-1</code>&quot;, or a fatal &quot;offset out of range&quot; error will occur.</p>

<p>If the term &quot;<code>$offset + $count</code>&quot; exceeds &quot;<code>$vector-&gt;Word_Size()-1</code>&quot;, all the words starting with word number &quot;<code>$offset</code>&quot; up to word number &quot;<code>$vector-&gt;Word_Size()-1</code>&quot; are simply cleared.</p>

</li>
<li><p><code>$vector-&gt;Chunk_Store($chunksize,$offset,$chunk);</code></p>

<p>This method allows you to set more than one bit at a time with different values.</p>

<p>You can access chunks (i.e., ranges of contiguous bits) between one and at most &quot;<code>Bit::Vector-&gt;Long_Bits()</code>&quot; bits wide.</p>

<p>In order to be portable, though, you should never use chunk sizes larger than 32 bits.</p>

<p>If the given &quot;<code>$chunksize</code>&quot; does not lie between &quot;<code>1</code>&quot; and &quot;<code>Bit::Vector-&gt;Long_Bits()</code>&quot;, a fatal &quot;chunk size out of range&quot; error will occur.</p>

<p>The method copies the &quot;<code>$chunksize</code>&quot; least significant bits from the value &quot;<code>$chunk</code>&quot; to the given bit vector, starting at bit position &quot;<code>$offset</code>&quot; and proceeding upwards until bit number &quot;<code>$offset+$chunksize-1</code>&quot;.</p>

<p>(I.e., bit number &quot;<code>0</code>&quot; of &quot;<code>$chunk</code>&quot; becomes bit number &quot;<code>$offset</code>&quot; in the given bit vector, and bit number &quot;<code>$chunksize-1</code>&quot; becomes bit number &quot;<code>$offset+$chunksize-1</code>&quot;.)</p>

<p>If the term &quot;<code>$offset+$chunksize-1</code>&quot; exceeds &quot;<code>$vector-&gt;Size()-1</code>&quot;, the corresponding superfluous (most significant) bits from &quot;<code>$chunk</code>&quot; are simply ignored.</p>

<p>Note that &quot;<code>$offset</code>&quot; itself must lie in the permitted range between &quot;<code>0</code>&quot; and &quot;<code>$vector-&gt;Size()-1</code>&quot;, or a fatal &quot;offset out of range&quot; error will occur.</p>

<p>This method (as well as the other &quot;<code>Chunk_</code>&quot; methods) is useful, for example, when you are reading in data in chunks of, say, 8 bits, which you need to access later, say, using 16 bits at a time (like audio CD wave files, for instance).</p>

</li>
<li><p><code>$chunk = $vector-&gt;Chunk_Read($chunksize,$offset);</code></p>

<p>This method allows you to read the values of more than one bit at a time.</p>

<p>You can read chunks (i.e., ranges of contiguous bits) between one and at most &quot;<code>Bit::Vector-&gt;Long_Bits()</code>&quot; bits wide.</p>

<p>In order to be portable, though, you should never use chunk sizes larger than 32 bits.</p>

<p>If the given &quot;<code>$chunksize</code>&quot; does not lie between &quot;<code>1</code>&quot; and &quot;<code>Bit::Vector-&gt;Long_Bits()</code>&quot;, a fatal &quot;chunk size out of range&quot; error will occur.</p>

<p>The method returns the &quot;<code>$chunksize</code>&quot; bits from the given bit vector starting at bit position &quot;<code>$offset</code>&quot; and proceeding upwards until bit number &quot;<code>$offset+$chunksize-1</code>&quot;.</p>

<p>(I.e., bit number &quot;<code>$offset</code>&quot; of the given bit vector becomes bit number &quot;<code>0</code>&quot; of the returned value, and bit number &quot;<code>$offset+$chunksize-1</code>&quot; becomes bit number &quot;<code>$chunksize-1</code>&quot;.)</p>

<p>If the term &quot;<code>$offset+$chunksize-1</code>&quot; exceeds &quot;<code>$vector-&gt;Size()-1</code>&quot;, the non-existent bits are simply not returned.</p>

<p>Note that &quot;<code>$offset</code>&quot; itself must lie in the permitted range between &quot;<code>0</code>&quot; and &quot;<code>$vector-&gt;Size()-1</code>&quot;, or a fatal &quot;offset out of range&quot; error will occur.</p>

</li>
<li><p><code>$vector-&gt;Chunk_List_Store($chunksize,@chunks);</code></p>

<p>This method allows you to fill the given bit vector with a list of data packets (&quot;chunks&quot;) of any size (&quot;<code>$chunksize</code>&quot;) you like (within certain limits).</p>

<p>In fact the given &quot;<code>$chunksize</code>&quot; must lie in the range between &quot;<code>1</code>&quot; and &quot;<code>Bit::Vector-&gt;Long_Bits()</code>&quot;, or a fatal &quot;chunk size out of range&quot; error will occur.</p>

<p>In order to be portable, though, you should never use chunk sizes larger than 32 bits.</p>

<p>The given bit vector is thereby filled in ascending order: The first chunk from the list (i.e., &quot;<code>$chunks[0]</code>&quot;) fills the &quot;<code>$chunksize</code>&quot; least significant bits, the next chunk from the list (&quot;<code>$chunks[1]</code>&quot;) fills the bits number &quot;<code>$chunksize</code>&quot; to number &quot;<code>2*$chunksize-1</code>&quot;, the third chunk (&quot;<code>$chunks[2]</code>&quot;) fills the bits number &quot;<code>2*$chunksize</code>&quot;, to number &quot;<code>3*$chunksize-1</code>&quot;, and so on.</p>

<p>If there a less chunks in the list than are needed to fill the entire bit vector, the remaining (most significant) bits are cleared, i.e., the previous contents of the given bit vector are always erased completely.</p>

<p>If there are more chunks in the list than are needed to fill the entire bit vector, and/or if a chunk extends beyond &quot;<code>$vector-&gt;Size()-1</code>&quot; (which happens whenever &quot;<code>$vector-&gt;Size()</code>&quot; is not a multiple of &quot;<code>$chunksize</code>&quot;), the superfluous chunks and/or bits are simply ignored.</p>

<p>The method is useful, for example (and among many other applications), for the conversion of packet sizes in a data stream.</p>

<p>This method can also be used to store an octal string in a given bit vector:</p>

<pre><code>  $vector-&gt;Chunk_List_Store(3, split(//, reverse $string));</code></pre>

<p>Note however that unlike the conversion methods &quot;<code>from_Hex()</code>&quot;, &quot;<code>from_Bin()</code>&quot;, &quot;<code>from_Dec()</code>&quot; and &quot;<code>from_Enum()</code>&quot;, this statement does not include any syntax checking, i.e., it may fail silently, without warning.</p>

<p>To perform syntax checking, add the following statements:</p>

<pre><code>  if ($string =~ /^[0-7]+$/)
  {
      # okay, go ahead with conversion as shown above
  }
  else
  {
      # error, string contains other than octal characters
  }</code></pre>

<p>Another application is to store a repetitive pattern in a given bit vector:</p>

<pre><code>  $pattern = 0xDEADBEEF;
  $length = 32;            # = length of $pattern in bits
  $size = $vector-&gt;Size();
  $factor = int($size / $length);
  if ($size % $length) { $factor++; }
  $vector-&gt;Chunk_List_Store($length, ($pattern) x $factor);</code></pre>

</li>
<li><p><code>@chunks = $vector-&gt;Chunk_List_Read($chunksize);</code></p>

<p>This method allows you to access the contents of the given bit vector in form of a list of data packets (&quot;chunks&quot;) of a size (&quot;<code>$chunksize</code>&quot;) of your choosing (within certain limits).</p>

<p>In fact the given &quot;<code>$chunksize</code>&quot; must lie in the range between &quot;<code>1</code>&quot; and &quot;<code>Bit::Vector-&gt;Long_Bits()</code>&quot;, or a fatal &quot;chunk size out of range&quot; error will occur.</p>

<p>In order to be portable, though, you should never use chunk sizes larger than 32 bits.</p>

<p>The given bit vector is thereby read in ascending order: The &quot;<code>$chunksize</code>&quot; least significant bits (bits number &quot;<code>0</code>&quot; to &quot;<code>$chunksize-1</code>&quot;) become the first chunk in the returned list (i.e., &quot;<code>$chunks[0]</code>&quot;). The bits number &quot;<code>$chunksize</code>&quot; to &quot;<code>2*$chunksize-1</code>&quot; become the next chunk in the list (&quot;<code>$chunks[1]</code>&quot;), and so on.</p>

<p>If &quot;<code>$vector-&gt;Size()</code>&quot; is not a multiple of &quot;<code>$chunksize</code>&quot;, the last chunk in the list will contain fewer bits than &quot;<code>$chunksize</code>&quot;.</p>

<p><b>BEWARE</b> that for large bit vectors and/or small values of &quot;<code>$chunksize</code>&quot;, the number of returned list elements can be extremely large! <b>BE CAREFUL!</b></p>

<p>You could blow up your application with lack of memory (each list element is a full-grown Perl scalar, internally, with an associated memory overhead for its administration!) or at least cause a noticeable, more or less long-lasting &quot;freeze&quot; of your application!</p>

<p>Possible applications:</p>

<p>The method is especially useful in the conversion of packet sizes in a data stream.</p>

<p>This method can also be used to convert a given bit vector to a string of octal numbers:</p>

<pre><code>  $string = reverse join(&#39;&#39;, $vector-&gt;Chunk_List_Read(3));</code></pre>

</li>
<li><p><code>$vector-&gt;Index_List_Remove(@indices);</code></p>

<p>This method allows you to specify a list of indices of bits which should be turned off in the given bit vector.</p>

<p>In fact this method is a shortcut for</p>

<pre><code>    foreach $index (@indices)
    {
        $vector-&gt;Bit_Off($index);
    }</code></pre>

<p>In contrast to all other import methods in this module, this method does <b>NOT</b> clear the given bit vector before processing its list of arguments.</p>

<p>Instead, this method allows you to accumulate the results of various consecutive calls.</p>

<p>(The same holds for the method &quot;<code>Index_List_Store()</code>&quot;. As a consequence, you can &quot;wipe out&quot; what you did using the method &quot;<code>Index_List_Remove()</code>&quot; by passing the identical argument list to the method &quot;<code>Index_List_Store()</code>&quot;.)</p>

</li>
<li><p><code>$vector-&gt;Index_List_Store(@indices);</code></p>

<p>This method allows you to specify a list of indices of bits which should be turned on in the given bit vector.</p>

<p>In fact this method is a shortcut for</p>

<pre><code>    foreach $index (@indices)
    {
        $vector-&gt;Bit_On($index);
    }</code></pre>

<p>In contrast to all other import methods in this module, this method does <b>NOT</b> clear the given bit vector before processing its list of arguments.</p>

<p>Instead, this method allows you to accumulate the results of various consecutive calls.</p>

<p>(The same holds for the method &quot;<code>Index_List_Remove()</code>&quot;. As a consequence, you can &quot;wipe out&quot; what you did using the method &quot;<code>Index_List_Store()</code>&quot; by passing the identical argument list to the method &quot;<code>Index_List_Remove()</code>&quot;.)</p>

</li>
<li><p><code>@indices = $vector-&gt;Index_List_Read();</code></p>

<p>This method returns a list of Perl scalars.</p>

<p>The list contains one scalar for each set bit in the given bit vector.</p>

<p><b>BEWARE</b> that for large bit vectors, this can result in a literally overwhelming number of list elements! <b>BE CAREFUL!</b> You could run out of memory or slow down your application considerably!</p>

<p>Each scalar contains the number of the index corresponding to the bit in question.</p>

<p>These indices are always returned in ascending order.</p>

<p>If the given bit vector is empty (contains only cleared bits) or if it has a length of zero (if it contains no bits at all), the method returns an empty list.</p>

<p>This method can be useful, for instance, to obtain a list of prime numbers:</p>

<pre><code>    $limit = 1000; # or whatever
    $vector = Bit::Vector-&gt;new($limit+1);
    $vector-&gt;Primes();
    @primes = $vector-&gt;Index_List_Read();</code></pre>

</li>
<li><p><code>$vec3-&gt;Or($vec1,$vec2);</code></p>

<p><code>$set3-&gt;Union($set1,$set2);</code></p>

<p>This method calculates the union of &quot;<code>$set1</code>&quot; and &quot;<code>$set2</code>&quot; and stores the result in &quot;<code>$set3</code>&quot;.</p>

<p>This is usually written as &quot;<code>$set3 = $set1 u $set2</code>&quot; in set theory (where &quot;u&quot; is the &quot;cup&quot; operator).</p>

<p>(On systems where the &quot;cup&quot; character is unavailable this operator is often denoted by a plus sign &quot;+&quot;.)</p>

<p>In-place calculation is also possible, i.e., &quot;<code>$set3</code>&quot; may be identical with &quot;<code>$set1</code>&quot; or &quot;<code>$set2</code>&quot; or both.</p>

</li>
<li><p><code>$vec3-&gt;And($vec1,$vec2);</code></p>

<p><code>$set3-&gt;Intersection($set1,$set2);</code></p>

<p>This method calculates the intersection of &quot;<code>$set1</code>&quot; and &quot;<code>$set2</code>&quot; and stores the result in &quot;<code>$set3</code>&quot;.</p>

<p>This is usually written as &quot;<code>$set3 = $set1 n $set2</code>&quot; in set theory (where &quot;n&quot; is the &quot;cap&quot; operator).</p>

<p>(On systems where the &quot;cap&quot; character is unavailable this operator is often denoted by an asterisk &quot;*&quot;.)</p>

<p>In-place calculation is also possible, i.e., &quot;<code>$set3</code>&quot; may be identical with &quot;<code>$set1</code>&quot; or &quot;<code>$set2</code>&quot; or both.</p>

</li>
<li><p><code>$vec3-&gt;AndNot($vec1,$vec2);</code></p>

<p><code>$set3-&gt;Difference($set1,$set2);</code></p>

<p>This method calculates the difference of &quot;<code>$set1</code>&quot; less &quot;<code>$set2</code>&quot; and stores the result in &quot;<code>$set3</code>&quot;.</p>

<p>This is usually written as &quot;<code>$set3 = $set1 \ $set2</code>&quot; in set theory (where &quot;\&quot; is the &quot;less&quot; operator).</p>

<p>In-place calculation is also possible, i.e., &quot;<code>$set3</code>&quot; may be identical with &quot;<code>$set1</code>&quot; or &quot;<code>$set2</code>&quot; or both.</p>

</li>
<li><p><code>$vec3-&gt;Xor($vec1,$vec2);</code></p>

<p><code>$set3-&gt;ExclusiveOr($set1,$set2);</code></p>

<p>This method calculates the symmetric difference of &quot;<code>$set1</code>&quot; and &quot;<code>$set2</code>&quot; and stores the result in &quot;<code>$set3</code>&quot;.</p>

<p>This can be written as &quot;<code>$set3 = ($set1 u $set2) \ ($set1 n $set2)</code>&quot; in set theory (the union of the two sets less their intersection).</p>

<p>When sets are implemented as bit vectors then the above formula is equivalent to the exclusive-or between corresponding bits of the two bit vectors (hence the name of this method).</p>

<p>Note that this method is also much more efficient than evaluating the above formula explicitly since it uses a built-in machine language instruction internally.</p>

<p>In-place calculation is also possible, i.e., &quot;<code>$set3</code>&quot; may be identical with &quot;<code>$set1</code>&quot; or &quot;<code>$set2</code>&quot; or both.</p>

</li>
<li><p><code>$vec2-&gt;Not($vec1);</code></p>

<p><code>$set2-&gt;Complement($set1);</code></p>

<p>This method calculates the complement of &quot;<code>$set1</code>&quot; and stores the result in &quot;<code>$set2</code>&quot;.</p>

<p>In &quot;big integer&quot; arithmetic, this is equivalent to calculating the one&#39;s complement of the number stored in the bit vector &quot;<code>$set1</code>&quot; in binary representation.</p>

<p>In-place calculation is also possible, i.e., &quot;<code>$set2</code>&quot; may be identical with &quot;<code>$set1</code>&quot;.</p>

</li>
<li><p><code>if ($set1-&gt;subset($set2))</code></p>

<p>Returns &quot;true&quot; (&quot;<code>1</code>&quot;) if &quot;<code>$set1</code>&quot; is a subset of &quot;<code>$set2</code>&quot; (i.e., completely contained in &quot;<code>$set2</code>&quot;) and &quot;false&quot; (&quot;<code>0</code>&quot;) otherwise.</p>

<p>This means that any bit which is set (&quot;<code>1</code>&quot;) in &quot;<code>$set1</code>&quot; must also be set in &quot;<code>$set2</code>&quot;, but &quot;<code>$set2</code>&quot; may contain set bits which are not set in &quot;<code>$set1</code>&quot;, in order for the condition of subset relationship to be true between these two sets.</p>

<p>Note that by definition, if two sets are identical, they are also subsets (and also supersets) of each other.</p>

</li>
<li><p><code>$norm = $set-&gt;Norm();</code></p>

<p>Returns the norm (number of bits which are set) of the given vector.</p>

<p>This is equivalent to the number of elements contained in the given set.</p>

<p>Uses a byte lookup table for calculating the number of set bits per byte, and thus needs a time for evaluation (and a number of loops) linearly proportional to the length of the given bit vector (in bytes).</p>

<p>This should be the fastest algorithm on average.</p>

</li>
<li><p><code>$norm = $set-&gt;Norm2();</code></p>

<p>Returns the norm (number of bits which are set) of the given vector.</p>

<p>This is equivalent to the number of elements contained in the given set.</p>

<p>This does the same as the method &quot;<code>Norm()</code>&quot; above, only with a different algorithm:</p>

<p>This method counts the number of set and cleared bits at the same time and will stop when either of them has been exhausted, thus needing at most half as many loops per machine word as the total number of bits in a machine word - in fact it will need a number of loops equal to the minimum of the number of set bits and the number of cleared bits.</p>

<p>This might be a faster algorithm than of the method &quot;<code>Norm()</code>&quot; above on some systems, depending on the system&#39;s architecture and the compiler and optimisation used, for bit vectors with sparse set bits and for bit vectors with sparse cleared bits (i.e., predominantly set bits).</p>

</li>
<li><p><code>$norm = $set-&gt;Norm3();</code></p>

<p>Returns the norm (number of bits which are set) of the given vector.</p>

<p>This is equivalent to the number of elements contained in the given set.</p>

<p>This does the same as the two methods &quot;<code>Norm()</code>&quot; and &quot;<code>Norm2()</code>&quot; above, however with a different algorithm.</p>

<p>In fact this is the implementation of the method &quot;<code>Norm()</code>&quot; used in previous versions of this module.</p>

<p>The method needs a number of loops per machine word equal to the number of set bits in that machine word.</p>

<p>Only for bit vectors with sparse set bits will this method be fast; it will depend on a system&#39;s architecture and compiler whether the method will be faster than any of the two methods above in such cases.</p>

<p>On average however, this is probably the slowest method of the three.</p>

</li>
<li><p><code>$min = $set-&gt;Min();</code></p>

<p>Returns the minimum of the given set, i.e., the minimum of all indices of all set bits in the given bit vector &quot;<code>$set</code>&quot;.</p>

<p>If the set is empty (no set bits), plus infinity (represented by the constant &quot;MAX_LONG&quot; on your system) is returned.</p>

<p>(This constant is usually <span style="white-space: nowrap;">2 ^ (n-1) - 1</span>, where &quot;<code>n</code>&quot; is the number of bits of an unsigned long on your machine.)</p>

</li>
<li><p><code>$max = $set-&gt;Max();</code></p>

<p>Returns the maximum of the given set, i.e., the maximum of all indices of all set bits in the given bit vector &quot;<code>$set</code>&quot;.</p>

<p>If the set is empty (no set bits), minus infinity (represented by the constant &quot;MIN_LONG&quot; on your system) is returned.</p>

<p>(This constant is usually <span style="white-space: nowrap;">-(2 ^ (n-1) - 1)</span> or <span style="white-space: nowrap;">-(2 ^ (n-1))</span>, where &quot;<code>n</code>&quot; is the number of bits of an unsigned long on your machine.)</p>

</li>
<li><p><code>$m3-&gt;Multiplication($r3,$c3,$m1,$r1,$c1,$m2,$r2,$c2);</code></p>

<p>This method multiplies two boolean matrices (stored as bit vectors) &quot;<code>$m1</code>&quot; and &quot;<code>$m2</code>&quot; and stores the result in matrix &quot;<code>$m3</code>&quot;.</p>

<p>The method uses the binary &quot;xor&quot; operation (&quot;<code>^</code>&quot;) as the boolean addition operator (&quot;<code>+</code>&quot;).</p>

<p>An exception is raised if the product of the number of rows and columns of any of the three matrices differs from the actual size of their underlying bit vector.</p>

<p>An exception is also raised if the numbers of rows and columns of the three matrices do not harmonize in the required manner:</p>

<pre><code>  rows3 == rows1
  cols3 == cols2
  cols1 == rows2</code></pre>

<p>This method is used by the module &quot;Math::MatrixBool&quot;.</p>

<p>See <a href="http://man.he.net/man3/Math::MatrixBool">Math::MatrixBool(3)</a> for details.</p>

</li>
<li><p><code>$m3-&gt;Product($r3,$c3,$m1,$r1,$c1,$m2,$r2,$c2);</code></p>

<p>This method multiplies two boolean matrices (stored as bit vectors) &quot;<code>$m1</code>&quot; and &quot;<code>$m2</code>&quot; and stores the result in matrix &quot;<code>$m3</code>&quot;.</p>

<p>This special method uses the binary &quot;or&quot; operation (&quot;<code>|</code>&quot;) as the boolean addition operator (&quot;<code>+</code>&quot;).</p>

<p>An exception is raised if the product of the number of rows and columns of any of the three matrices differs from the actual size of their underlying bit vector.</p>

<p>An exception is also raised if the numbers of rows and columns of the three matrices do not harmonize in the required manner:</p>

<pre><code>  rows3 == rows1
  cols3 == cols2
  cols1 == rows2</code></pre>

<p>This method is used by the module &quot;Math::MatrixBool&quot;.</p>

<p>See <a href="http://man.he.net/man3/Math::MatrixBool">Math::MatrixBool(3)</a> for details.</p>

</li>
<li><p><code>$matrix-&gt;Closure($rows,$cols);</code></p>

<p>This method calculates the reflexive transitive closure of the given boolean matrix (stored as a bit vector) using Kleene&#39;s algoritm.</p>

<p>(See <a href="http://man.he.net/man3/Math::Kleene">Math::Kleene(3)</a> for a brief introduction into the theory behind Kleene&#39;s algorithm.)</p>

<p>The reflexive transitive closure answers the question whether a path exists between any two vertices of a graph whose edges are given as a matrix:</p>

<p>If a (directed) edge exists going from vertex &quot;i&quot; to vertex &quot;j&quot;, then the element in the matrix with coordinates (i,j) is set to &quot;<code>1</code>&quot; (otherwise it remains set to &quot;<code>0</code>&quot;).</p>

<p>If the edges are undirected, the resulting matrix is symmetric, i.e., elements (i,j) and (j,i) always contain the same value.</p>

<p>The matrix representing the edges of the graph only answers the question whether an <b>EDGE</b> exists between any two vertices of the graph or not, whereas the reflexive transitive closure answers the question whether a <b>PATH</b> (a series of adjacent edges) exists between any two vertices of the graph!</p>

<p>Note that the contents of the given matrix are modified by this method, so make a copy of the initial matrix in time if you are going to need it again later.</p>

<p>An exception is raised if the given matrix is not quadratic, i.e., if the number of rows and columns of the given matrix is not identical.</p>

<p>An exception is also raised if the product of the number of rows and columns of the given matrix differs from the actual size of its underlying bit vector.</p>

<p>This method is used by the module &quot;Math::MatrixBool&quot;.</p>

<p>See <a href="http://man.he.net/man3/Math::MatrixBool">Math::MatrixBool(3)</a> for details.</p>

</li>
<li><p><code>$matrix2-&gt;Transpose($rows2,$cols2,$matrix1,$rows1,$cols1);</code></p>

<p>This method calculates the transpose of a boolean matrix &quot;<code>$matrix1</code>&quot; (stored as a bit vector) and stores the result in matrix &quot;<code>$matrix2</code>&quot;.</p>

<p>The transpose of a boolean matrix, representing the edges of a graph, can be used for finding the strongly connected components of that graph.</p>

<p>An exception is raised if the product of the number of rows and columns of any of the two matrices differs from the actual size of its underlying bit vector.</p>

<p>An exception is also raised if the following conditions are not met:</p>

<pre><code>  rows2 == cols1
  cols2 == rows1</code></pre>

<p>Note that in-place processing (&quot;<code>$matrix1</code>&quot; and &quot;<code>$matrix2</code>&quot; are identical) is only possible if the matrix is quadratic. Otherwise, a fatal &quot;matrix is not quadratic&quot; error will occur.</p>

<p>This method is used by the module &quot;Math::MatrixBool&quot;.</p>

<p>See <a href="http://man.he.net/man3/Math::MatrixBool">Math::MatrixBool(3)</a> for details.</p>

</li>
</ul>

<h1 id="SEE-ALSO"><a id="SEE"></a>SEE ALSO</h1>

<p>Bit::Vector::Overload(3), Bit::Vector::String(3), Storable(3).</p>

<p>Set::IntRange(3), Math::MatrixBool(3), Math::MatrixReal(3), DFA::Kleene(3), Math::Kleene(3), Graph::Kruskal(3).</p>

<h1 id="VERSION">VERSION</h1>

<p>This man page documents &quot;Bit::Vector&quot; version 7.4.</p>

<h1 id="AUTHOR">AUTHOR</h1>

<pre><code>  Steffen Beyer
  mailto:STBEY@cpan.org
  http://www.engelschall.com/u/sb/download/</code></pre>

<h1 id="COPYRIGHT">COPYRIGHT</h1>

<p>Copyright (c) 1995 - 2013 by Steffen Beyer. All rights reserved.</p>

<h1 id="LICENSE">LICENSE</h1>

<p>This package is free software; you can redistribute it and/or modify it under the same terms as Perl itself, i.e., under the terms of the &quot;Artistic License&quot; or the &quot;GNU General Public License&quot;.</p>

<p>The C library at the core of this Perl module can additionally be redistributed and/or modified under the terms of the &quot;GNU Library General Public License&quot;.</p>

<p>Please refer to the files &quot;Artistic.txt&quot;, &quot;GNU_GPL.txt&quot; and &quot;GNU_LGPL.txt&quot; in this distribution for details!</p>

<h1 id="DISCLAIMER">DISCLAIMER</h1>

<p>This package is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.</p>

<p>See the &quot;GNU General Public License&quot; for more details.</p></div>

<div id="metacpan_install-instructions-dialog" class="modal fade">
  <div class="modal-dialog">
    <div class="modal-content">
      <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
        <h4 class="modal-title">Module Install Instructions</h4>
      </div>
      <div class="modal-body">
        <p>To install Bit::Vector, copy and paste the appropriate command in to your terminal.</p>
        <p><a href="https://metacpan.org/dist/App-cpanminus/view/bin/cpanm">cpanm</a></p>
        <pre><code>cpanm Bit::Vector</code></pre>
        <p><a href="https://metacpan.org/pod/CPAN">CPAN shell</a></p>
        <pre><code>perl -MCPAN -e shell
install Bit::Vector</code></pre>
        <p>For more information on module installation, please visit <a href="https://www.cpan.org/modules/INSTALL.html">the detailed CPAN module installation guide</a>.</p>
      </div>
      <div class="modal-footer">
        <a href="./Bit::Vector.html#" data-dismiss="modal" class="btn">Close</a>
      </div>
    </div>
  </div>
</div>
          </main>
          <div class="content-pagination">
          </div>
        </div>
        <footer class="footer">
          <div class="footer-container">
            <div class="footer-social">
              <div class="footer-link footer-logo">
                <a href="https://metacpan.org/">
                  <img src="https://metacpan.org/static/images/metacpan-logo.svg" alt="MetaCPAN" />
                </a>
              </div>
              <a class="footer-social-link" href="https://github.com/metacpan">
                <i class="fab fa-github-square"></i>
              </a>
              <a class="footer-social-link" href="https://fosstodon.org/@metacpan">
                <i class="fab fa-mastodon"></i>
              </a>
            </div>
            <div class="footer-links">
              <div class="footer-link">
                  <a href="https://metacpan.org/about">About</a>
              </div>
              <div class="footer-link">
                  <a href="https://metacpan.org/about/sponsors">Sponsor</a>
              </div>
              <div class="footer-link">
                  <a href="https://grep.metacpan.org">grep::cpan</a>
              </div>
              <div class="footer-link">
                  <a href="https://metacpan.org/recent">Recent</a>
              </div>
              <div class="footer-link">
                  <a href="https://metacpan.org/about/faq">FAQ</a>
              </div>
              <div class="footer-link">
                  <a href="https://metacpan.org/tools">Tools</a>
              </div>
              <div class="footer-link">
                  <a href="https://fastapi.metacpan.org/">API</a>
              </div>
              <div class="footer-link">
                  <a href="https://www.perl.org/">Perl.org</a>
              </div>
            </div>
            <div class="footer-sponsors">
              <a class="footer-sponsor-link" target="_blank" href="https://www.bytemark.co.uk/" rel="noopener">
                <img class="footer-sponsor-bytemark" src="https://metacpan.org/static/images/sponsors/bytemark_logo.svg" alt="Bytemark logo">
              </a>
              <a class="footer-sponsor-link" target="_blank" href="https://www.liquidweb.com/" rel="noopener">
                <img class="footer-sponsor-liquidweb" src="https://metacpan.org/static/images/sponsors/liquidweb_logo.png" alt="liquidweb logo">
              </a>
              <a class="footer-sponsor-link" target="_blank" href="https://deriv.com/careers/" rel="noopener">
                <img class="footer-sponsor-deriv" src="https://metacpan.org/static/images/sponsors/deriv.svg" alt="Deriv logo">
              </a>
              <a class="footer-sponsor-link" target="_blank" href="https://geocode.xyz" rel="noopener">
                <img class="footer-sponsor-geocode" src="https://metacpan.org/static/images/sponsors/geocodelogo.svg" alt="Geocode logo">
              </a>
              <a class="footer-sponsor-link" target="_blank" href="https://www.fastly.com/" rel="noopener">
                <img class="footer-sponsor-fastly" src="https://metacpan.org/static/images/sponsors/fastly_logo.svg" alt="Fastly logo">
              </a>
              <a class="footer-sponsor-link" target="_blank" href="https://opencagedata.com" rel="noopener">
                <img class="footer-sponsor-opencage" src="https://metacpan.org/static/images/sponsors/open-cage.svg" alt="OpenCage logo">
              </a>
            </div>
          </div>
        </footer>
        <div class="modal fade" tabindex="-1" role="dialog" id="metacpan_keyboard-shortcuts">
          <div class="modal-dialog">
            <div class="modal-content">
              <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal">&times;</button>
                <h4 class="modal-title">Keyboard Shortcuts</h4>
              </div>
              <div class="modal-body row">
<div class="col-md-6">
  <table class="table keyboard-shortcuts">
    <thead>
      <tr>
        <th></th>
        <th>Global</th>
      </tr>
    </thead>
    <tbody>
      <tr>
        <td class="keys">
          <kbd>s</kbd>
        </td>
        <td>Focus search bar</td>
      </tr>
      <tr>
        <td class="keys">
          <kbd>?</kbd>
        </td>
        <td>Bring up this help dialog</td>
      </tr>
    </tbody>
  </table>

  <table class="table keyboard-shortcuts">
    <thead>
      <tr>
        <th></th>
        <th>GitHub</th>
      </tr>
    </thead>
    <tbody>
      <tr>
        <td class="keys">
          <kbd>g</kbd> <kbd>p</kbd>
        </td>
        <td>Go to pull requests</td>
      </tr>
      <tr>
        <td class="keys">
          <kbd>g</kbd> <kbd>i</kbd>
        </td>
        <td>go to github issues (only if github is preferred repository)</td>
      </tr>
    </tbody>
  </table>
</div>

<div class="col-md-6">
  <table class="table keyboard-shortcuts">
    <thead>
      <tr>
        <th></th>
        <th>POD</th>
      </tr>
    </thead>
    <tbody>
      <tr>
        <td class="keys">
          <kbd>g</kbd> <kbd>a</kbd>
        </td>
        <td>Go to author</td>
      </tr>
      <tr>
        <td class="keys">
          <kbd>g</kbd> <kbd>c</kbd>
        </td>
        <td>Go to changes</td>
      </tr>
      <tr>
        <td class="keys">
          <kbd>g</kbd> <kbd>i</kbd>
        </td>
        <td>Go to issues</td>
      </tr>
      <tr>
        <td class="keys">
          <kbd>g</kbd> <kbd>d</kbd>
        </td>
        <td>Go to dist</td>
      </tr>
      <tr>
        <td class="keys">
          <kbd>g</kbd> <kbd>r</kbd>
        </td>
        <td>Go to repository/SCM</td>
      </tr>
      <tr>
        <td class="keys">
          <kbd>g</kbd> <kbd>s</kbd>
        </td>
        <td>Go to source</td>
      </tr>
      <tr>
        <td class="keys">
          <kbd>g</kbd> <kbd>b</kbd>
        </td>
        <td>Go to file browse</td>
      </tr>

    </tbody>
  </table>
</div>

<div class="col-md-12">
  <table class="table keyboard-shortcuts">
    <thead>
      <tr>
        <th></th>
        <th>Search terms</th>
      </tr>
    </thead>
    <tbody>
      <tr>
        <td><em>module:</em> (e.g. <a href="https://metacpan.org/search?q=module%3APlugin">module:Plugin</a>)</td>
      </tr>
      <tr>
        <td><em>distribution:</em> (e.g. <a href="https://metacpan.org/search?q=distribution%3ADancer+auth">distribution:Dancer auth</a>)</td>
      </tr>
      <tr>
        <td><em>author:</em> (e.g. <a href="https://metacpan.org/search?q=author%3ASONGMU+Redis">author:SONGMU Redis</a>)</td>
      </tr>
      <tr>
        <td><em>version:</em> (e.g. <a href="https://metacpan.org/search?q=version%3A1.00">version:1.00</a>)</td>
      </tr>
    </tbody>
  </table>
</div>
              </div>
              <div class="modal-footer"></div>
            </div>
          </div>
        </div>
    </body>
</html>
